History

avcodec/jpegxl_parser: fix reading lz77-pair as initial entropy symbol

The JPEG XL parser has an entropy decoder inside, which supports LZ77 length-distance pairs. If the first symbol from the entropy stream is an LZ77 pair, the bitstream is invalid, so we should abort immediately rather than attempt to read it anyway (which would read from the uninitialized starting window).

Leo Izen committed 2 years ago

Commit 18883fb1 parent a5dabfc1 file · +3 −0Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/jpegxl_parser.c+3−0
@@ -352,6 +352,8 @@ static int decode_hybrid_varlen_uint(GetBitContext *gb, JXLEntropyDecoder *dec, · 351 unmodified lines
352352
353353 if (bundle->lz77_enabled && token >= bundle->lz77_min_symbol) {
354354 const JXLSymbolDistribution *lz77dist = &bundle->dists[bundle->cluster_map[bundle->num_dist - 1]];
355+ if (!dec->num_decoded)
356+ return AVERROR_INVALIDDATA;
355357 ret = read_hybrid_uint(gb, &bundle->lz_len_conf, token - bundle->lz77_min_symbol, &dec->num_to_copy);
356358 if (ret < 0)
357359 return ret;
@@ -531,6 +533,7 @@ static int read_dist_clustering(GetBitContext *gb, JXLEntropyDecoder *dec, JXLDi · 173 unmodified lines
531533 dec->state = -1;
532534 /* it's not going to necessarily be zero after reading */
533535 dec->num_to_copy = 0;
536+ dec->num_decoded = 0;
534537 dist_bundle_close(&nested);
535538 if (use_mtf) {
536539 uint8_t mtf[256];

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