SerenityOS / serenity

The Serenity Operating System 🐞
https://serenityos.org
BSD 2-Clause "Simplified" License
30.48k stars 3.18k forks source link

"Reached an unsupported marker" on jpeg other decoders can decode #22779

Open nico opened 8 months ago

nico commented 8 months ago

image-0024

With some additional debug logging (https://github.com/nico/serenity/pull/new/jpeg-debug):

% Build/lagom/bin/image -o out.png image-0024.jpg    
JPEG: trying to read marker at 0x1000
JPEG: trying to read marker at 0x1002
JPEG: trying to read marker at 0x1014
JPEG: trying to read marker at 0x1035
JPEG: trying to read marker at 0x107a
JPEG: trying to read marker at 0x1131
JPEG: trying to read marker at 0x1176
JPEG: trying to read marker at 0x1197
JPEG: trying to read marker at 0x124e
Restart marker: 1760
JPEG: trying to read marker at 0x1254
Component subsampling: 2, 2
Component subsampling: 1, 1
Component subsampling: 1, 1
Image width: 3507
Image height: 2480
Macroblocks in a row: 440
Macroblocks in a column: 310
Macroblock meta padded total: 136400
JPEG: trying to read marker at 0x1267
SOS Bytes to read: 10
Components in scan: 1 2 3 
Start of Selection: 0, End of Selection: 63, Successive Approximation High: 0, Successive Approximation Low: 0
Restarting decoder at macroblock 7040, offset 0x33bf
Restarting decoder at macroblock 14080, offset 0x6d55
Restarting decoder at macroblock 21120, offset 0xe91c
Restarting decoder at macroblock 28160, offset 0x161c7
Restarting decoder at macroblock 35200, offset 0x1db6a
Restarting decoder at macroblock 42240, offset 0x258d0
Restarting decoder at macroblock 49280, offset 0x2d5be
Restarting decoder at macroblock 56320, offset 0x352c1
Restarting decoder at macroblock 63360, offset 0x3ca24
Restarting decoder at macroblock 70400, offset 0x45035
Restarting decoder at macroblock 77440, offset 0x4c5a8
Restarting decoder at macroblock 84480, offset 0x538d3
Restarting decoder at macroblock 91520, offset 0x5aa12
Restarting decoder at macroblock 98560, offset 0x61c59
Restarting decoder at macroblock 105600, offset 0x68a80
Restarting decoder at macroblock 112640, offset 0x6f462
Restarting decoder at macroblock 119680, offset 0x75cdb
Restarting decoder at macroblock 126720, offset 0x7a04b
Restarting decoder at macroblock 133760, offset 0x7c06f
JPEG: trying to read marker at 0x7cac6
JPEG: Unsupported marker 0x0028 before offset 0x7cac8
Runtime error: Reached an unsupported marker

Looks like there's some trailing data (…or we read to little data) before the JPEG_EOI after we're done with decode_huffman_stream().

nico commented 8 months ago

(This is responsible for all this diag in test_pdf.py 0000:

Internal error while processing PDF file: Reached an unsupported marker, in 1 files, on 8 pages, 8 times
  /Users/thakis/Downloads/0000/0000930.pdf 1 2 3 4 5 6 7 8

)

LucasChollet commented 8 months ago

We decode it correctly (AFAICS) with: https://github.com/SerenityOS/serenity/pull/19571

And it seems to be the correct fix, as GIMP reports this error when I open the file: Corrupt JPEG data: 4394 extraneous bytes before marker 0xd9