std/jpeg: add "#short SOS bitstream"

This commit is contained in:
Nigel Tao committed 2024-08-24 17:01:28 +10:00
1 parent a824c55c3d
commit 819742cfac
3 files changed
+15 -4

No files matched your search

+3 -1
View File
@@ -10034,6 +10034,7 @@ extern const char wuffs_jpeg__error__bad_scan_count[];
extern const char wuffs_jpeg__error__missing_huffman_table[];
extern const char wuffs_jpeg__error__missing_quantization_table[];
extern const char wuffs_jpeg__error__rejected_progressive_jpeg[];
extern const char wuffs_jpeg__error__short_sos_bitstream[];
extern const char wuffs_jpeg__error__truncated_input[];
extern const char wuffs_jpeg__error__unsupported_arithmetic_coding[];
extern const char wuffs_jpeg__error__unsupported_color_model[];
@@ -46681,6 +46682,7 @@ const char wuffs_jpeg__error__bad_scan_count[] = "#jpeg: bad scan count";
const char wuffs_jpeg__error__missing_huffman_table[] = "#jpeg: missing Huffman table";
const char wuffs_jpeg__error__missing_quantization_table[] = "#jpeg: missing Quantization table";
const char wuffs_jpeg__error__rejected_progressive_jpeg[] = "#jpeg: rejected progressive JPEG";
const char wuffs_jpeg__error__short_sos_bitstream[] = "#jpeg: short SOS bitstream";
const char wuffs_jpeg__error__truncated_input[] = "#jpeg: truncated input";
const char wuffs_jpeg__error__unsupported_arithmetic_coding[] = "#jpeg: unsupported arithmetic coding";
const char wuffs_jpeg__error__unsupported_color_model[] = "#jpeg: unsupported color model";
@@ -50862,7 +50864,7 @@ wuffs_jpeg__decoder__decode_sos(
if (v_bitstream_length < ((uint32_t)(self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri))) {
break;
} else if (self->private_impl.f_bitstream_padding == 0u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker);
status = wuffs_base__make_status(wuffs_jpeg__error__short_sos_bitstream);
goto exit;
} else if ((a_src && a_src->meta.closed) && ! self->private_impl.f_bitstream_is_closed) {
if (self->private_impl.f_bitstream_wi < 1024u) {
+10 -2
View File
@@ -72,10 +72,18 @@ handle() {
# Image file format specifications cover how to correctly decode complete
# input but usually do not mandate exactly how to decode truncated input.
# Print "trunc" vs "other" to distinguish these cases.
#
# A short SOS (Start Of Scan) bitstream is similar. Strictly speaking, such
# JPEG images are invalid. In practice, decoders have some discretion in how
# many implicit zero bits to produce before giving up. Giving up effectively
# truncates the input, even if we haven't reached the actual end of file.
#
# Print "trunc" vs "sSOSb" vs "other" to distinguish these cases.
local error=$(gen/bin/example-convert-to-nia -output-netpbm <$1 2>&1 >/dev/null)
if [[ $error =~ :\ truncated.input$ ]]; then
if [[ $error =~ :\ truncated\ input$ ]]; then
echo "Differ (trunc) $1"
elif [[ $error =~ :\ short\ SOS\ bitstream$ ]]; then
echo "Differ (sSOSb) $1"
else
echo "Differ (other) $1"
result=1
+2 -1
View File
@@ -19,6 +19,7 @@ pub status "#bad scan count"
pub status "#missing Huffman table"
pub status "#missing Quantization table"
pub status "#rejected progressive JPEG"
pub status "#short SOS bitstream"
pub status "#truncated input"
pub status "#unsupported arithmetic coding"
pub status "#unsupported color model"
@@ -1370,7 +1371,7 @@ pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, wo
if bitstream_length < (this.bitstream_wi ~mod- this.bitstream_ri) {
break.fill_bitstream
} else if this.bitstream_padding == 0 {
return "#bad SOS marker"
return "#short SOS bitstream"
} else if args.src.is_closed() and (not this.bitstream_is_closed) {
if this.bitstream_wi < (0x800 / 2) {
assert this.bitstream_wi <= (this.bitstream_wi + 264) via "a <= (a + b): 0 <= b"()