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

Showing the changes to libavcodec (2 of 2 files). Show all

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
462 return AVERROR_BUFFER_TOO_SMALL;462 return AVERROR_BUFFER_TOO_SMALL;
463 463
464 size = bytestream2_get_be32(&gb);464 size = bytestream2_get_be32(&gb);
465 tag = bytestream2_get_le32(&gb);
466
465 if (size == 1) {467 if (size == 1) {
466 if (bytestream2_get_bytes_left(&gb) < 12)468 if (bytestream2_get_bytes_left(&gb) < 8)
467 return AVERROR_BUFFER_TOO_SMALL;469 return AVERROR_BUFFER_TOO_SMALL;
468 size = bytestream2_get_be64(&gb);470 size = bytestream2_get_be64(&gb);
469 head_size = 16;471 head_size = 16;
@@ -474,8 +476,6 @@ int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_l · 4 unmodified lines
474 if (size)476 if (size)
475 size -= head_size;477 size -= head_size;
476 478
477 tag = bytestream2_get_le32(&gb);
478
479 if (tag == MKTAG('j','x','l','p')) {479 if (tag == MKTAG('j','x','l','p')) {
480 uint32_t idx;480 uint32_t idx;
481 if (bytestream2_get_bytes_left(&gb) < 4)481 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
1342 1342
1343 while (1) {1343 while (1) {
1344 uint64_t size;1344 uint64_t size;
1345 int head_size = 4;1345 int head_size = 8;
1346 1346
1347 if (bytestream2_peek_le16(&gb) == FF_JPEGXL_CODESTREAM_SIGNATURE_LE)1347 if (bytestream2_peek_le16(&gb) == FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
1348 break;1348 break;
@@ -1353,16 +1353,17 @@ static int skip_boxes(JXLParseContext *ctx, const uint8_t *buf, int buf_size) · 4 unmodified lines
1353 return AVERROR_BUFFER_TOO_SMALL;1353 return AVERROR_BUFFER_TOO_SMALL;
1354 1354
1355 size = bytestream2_get_be32(&gb);1355 size = bytestream2_get_be32(&gb);
1356 bytestream2_skip(&gb, 4); // tag
1356 if (size == 1) {1357 if (size == 1) {
1357 if (bytestream2_get_bytes_left(&gb) < 12)1358 if (bytestream2_get_bytes_left(&gb) < 8)
1358 return AVERROR_BUFFER_TOO_SMALL;1359 return AVERROR_BUFFER_TOO_SMALL;
1359 size = bytestream2_get_be64(&gb);1360 size = bytestream2_get_be64(&gb);
1360 head_size = 12;1361 head_size = 16;
1361 }1362 }
1362 if (!size)1363 if (!size)
1363 return AVERROR_INVALIDDATA;1364 return AVERROR_INVALIDDATA;
1364 /* invalid ISOBMFF size */1365 /* invalid ISOBMFF size */
1365 if (size <= head_size + 4 || size > INT_MAX - ctx->skip)1366 if (size <= head_size || size > INT_MAX - ctx->skip)
1366 return AVERROR_INVALIDDATA;1367 return AVERROR_INVALIDDATA;
1367 1368
1368 ctx->skip += size;1369 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