1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +00:00

LibGfx: Return from scan_huffman_stream before JPEG_EOI

As a JPEG file can contain multiples scans, we should return from
`scan_huffman_stream` on all new markers (except restart markers) and
not only `JPEG_EOI`.
This commit is contained in:
Lucas CHOLLET 2023-02-19 22:35:10 -05:00 committed by Andreas Kling
parent f1aa189027
commit c0c48afe06

View file

@ -1217,15 +1217,15 @@ static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPEGLoading
continue; continue;
} }
Marker marker = 0xFF00 | current_byte; Marker marker = 0xFF00 | current_byte;
if (marker == JPEG_EOI)
return {};
if (marker >= JPEG_RST0 && marker <= JPEG_RST7) { if (marker >= JPEG_RST0 && marker <= JPEG_RST7) {
context.huffman_stream.stream.append(marker); context.huffman_stream.stream.append(marker);
current_byte = TRY(stream.read_value<u8>()); current_byte = TRY(stream.read_value<u8>());
continue; continue;
} }
dbgln_if(JPEG_DEBUG, "{}: Invalid marker: {:x}!", TRY(stream.tell()), marker);
return Error::from_string_literal("Invalid marker"); // Rollback the marker we just read
TRY(stream.seek(-2, AK::SeekMode::FromCurrentPosition));
return {};
} else { } else {
context.huffman_stream.stream.append(last_byte); context.huffman_stream.stream.append(last_byte);
} }