From 0d30ebcac259df313916b5a7b96add38070c2a7e Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Date: Tue, 8 Nov 2022 13:45:40 +0530 Subject: Fix how ExifInterface creates VP8X chunks for WebP files The current code reads alpha into an int, doesn't shift it back to the least-significant-bit, and then shifts that value 4 more bits before writing to the VP8X 'flags' byte. This results in setting the MSB of the flags byte, which is a reserved bit that must always be zero, resulting in an invalid file. VP8X part of WebP spec: https://developers.google.com/speed/webp/docs/riff_container#extended_file_format Test: ExifInterfaceTest (after removing the suppression for this bug) Bug: 253622642 Change-Id: I42469a479c94442eb395124c4eac174bd9ab6e09 --- media/java/android/media/ExifInterface.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java index 74e0fc1f9677..252b86254342 100644 --- a/media/java/android/media/ExifInterface.java +++ b/media/java/android/media/ExifInterface.java @@ -3825,7 +3825,7 @@ public class ExifInterface { int widthAndHeight = 0; int width = 0; int height = 0; - int alpha = 0; + boolean alpha = false; // Save VP8 frame data for later byte[] vp8Frame = new byte[3]; @@ -3860,7 +3860,7 @@ public class ExifInterface { width = ((widthAndHeight << 18) >> 18) + 1; height = ((widthAndHeight << 4) >> 18) + 1; // Retrieve alpha bit - alpha = widthAndHeight & (1 << 3); + alpha = (widthAndHeight & (1 << 28)) != 0; bytesToRead -= (1 /* VP8L signature */ + 4); } @@ -3868,10 +3868,12 @@ public class ExifInterface { nonHeaderOutputStream.write(WEBP_CHUNK_TYPE_VP8X); nonHeaderOutputStream.writeInt(WEBP_CHUNK_TYPE_VP8X_DEFAULT_LENGTH); byte[] data = new byte[WEBP_CHUNK_TYPE_VP8X_DEFAULT_LENGTH]; + // ALPHA flag + if (alpha) { + data[0] = (byte) (data[0] | (1 << 4)); + } // EXIF flag data[0] = (byte) (data[0] | (1 << 3)); - // ALPHA flag - data[0] = (byte) (data[0] | (alpha << 4)); // VP8X stores Width - 1 and Height - 1 values width -= 1; height -= 1; -- cgit v1.2.3-59-g8ed1b