Skip to content

Commit f7b5930

Browse files
committed
Switch to readNBytes to retrieve header content consistently
1 parent 63c85c1 commit f7b5930

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class MediaHelper {
5050
private static final int WEBP_CHUNK_TYPE_OFFSET = 12;
5151
private static final int WEBP_CHUNK_TYPE_LENGTH = 4;
5252
private static final int WEBP_FLAGS_BYTE_OFFSET = 20;
53+
private static final int WEBP_HEADER_SIZE = 21;
5354
private static final int WEBP_ANIMATION_BIT_MASK = 0x02;
5455
private static final String WEBP_EXTENDED_FILE_FORMAT = "VP8X";
5556

@@ -320,8 +321,8 @@ private static boolean isSupportedImage(File image, String mimeType) {
320321
*/
321322
private static boolean isAnimatedWebp(File file) {
322323
try (var fileInputStream = new FileInputStream(file)) {
323-
var header = new byte[WEBP_FLAGS_BYTE_OFFSET + 1];
324-
if (fileInputStream.read(header) < 21) {
324+
var header = fileInputStream.readNBytes(WEBP_HEADER_SIZE);
325+
if (header.length < WEBP_HEADER_SIZE) {
325326
return false;
326327
}
327328

0 commit comments

Comments
 (0)