History

avcodec/jpegxl_parse{,r}: use correct ISOBMFF extended size location

According to ISO/IEC 14996-12, size == 1 means a 64-bit extended-size field occurs *after* the 32-bit box type, not before. This fix should allow correct parsing of JXL files with extended-size boxes.

Leo Izen committed 2 years ago

Commit 019b3ea1 parent 35a555e2 files · +8 −7Browse files

Unified · Split

2 files
  1. libavcodec/jpegxl_parse.c +3 −3
  2. libavcodec/jpegxl_parser.c +5 −4
libavcodec/jpegxl_parse.c+3−3
@@ -462,8 +462,10 @@ int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_l · 461 unmodified lines
462462 return AVERROR_BUFFER_TOO_SMALL;
463463
464464 size = bytestream2_get_be32(&gb);
465+ tag = bytestream2_get_le32(&gb);
466+
465467 if (size == 1) {
466− if (bytestream2_get_bytes_left(&gb) < 12)
468+ if (bytestream2_get_bytes_left(&gb) < 8)
467469 return AVERROR_BUFFER_TOO_SMALL;
468470 size = bytestream2_get_be64(&gb);
469471 head_size = 16;
@@ -474,8 +476,6 @@ int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_l · 4 unmodified lines
474476 if (size)
475477 size -= head_size;
476478
477− tag = bytestream2_get_le32(&gb);
478−
479479 if (tag == MKTAG('j','x','l','p')) {
480480 uint32_t idx;
481481 if (bytestream2_get_bytes_left(&gb) < 4)
libavcodec/jpegxl_parser.c+5−4
@@ -1342,7 +1342,7 @@ static int skip_boxes(JXLParseContext *ctx, const uint8_t *buf, int buf_size) · 1341 unmodified lines
13421342
13431343 while (1) {
13441344 uint64_t size;
1345− int head_size = 4;
1345+ int head_size = 8;
13461346
13471347 if (bytestream2_peek_le16(&gb) == FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
13481348 break;
@@ -1353,16 +1353,17 @@ static int skip_boxes(JXLParseContext *ctx, const uint8_t *buf, int buf_size) · 4 unmodified lines
13531353 return AVERROR_BUFFER_TOO_SMALL;
13541354
13551355 size = bytestream2_get_be32(&gb);
1356+ bytestream2_skip(&gb, 4); // tag
13561357 if (size == 1) {
1357− if (bytestream2_get_bytes_left(&gb) < 12)
1358+ if (bytestream2_get_bytes_left(&gb) < 8)
13581359 return AVERROR_BUFFER_TOO_SMALL;
13591360 size = bytestream2_get_be64(&gb);
1360− head_size = 12;
1361+ head_size = 16;
13611362 }
13621363 if (!size)
13631364 return AVERROR_INVALIDDATA;
13641365 /* invalid ISOBMFF size */
1365− if (size <= head_size + 4 || size > INT_MAX - ctx->skip)
1366+ if (size <= head_size || size > INT_MAX - ctx->skip)
13661367 return AVERROR_INVALIDDATA;
13671368
13681369 ctx->skip += size;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t