From cf3835b29bc13b1713ef511b6948ba247b4e7594 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 21 Apr 2023 10:29:58 -0400 Subject: [PATCH] LibGfx/JPEG: Make non-zero-terminated APPn starts non-fatal Necessary but not sufficient for #18456. --- Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index 487e38fd2a..60a2e1f50f 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -835,6 +835,7 @@ static ErrorOr read_huffman_table(Stream& stream, JPEGLoadingContext& cont static ErrorOr read_icc_profile(Stream& stream, JPEGLoadingContext& context, int bytes_to_read) { + // https://www.color.org/technotes/ICC-Technote-ProfileEmbedding.pdf, page 5, "JFIF". if (bytes_to_read <= 2) return Error::from_string_literal("icc marker too small"); @@ -937,6 +938,7 @@ static ErrorOr read_colour_encoding(Stream& stream, [[maybe_unused]] JPEGL static ErrorOr read_app_marker(Stream& stream, JPEGLoadingContext& context, int app_marker_number) { + // B.2.4.6 - Application data syntax i32 bytes_to_read = TRY(stream.read_value>()); if (bytes_to_read <= 2) @@ -945,8 +947,10 @@ static ErrorOr read_app_marker(Stream& stream, JPEGLoadingContext& context StringBuilder builder; for (;;) { - if (bytes_to_read == 0) - return Error::from_string_literal("app marker size too small for identifier"); + if (bytes_to_read == 0) { + dbgln_if(JPEG_DEBUG, "app marker {} does not start with zero-terminated string", app_marker_number); + return {}; + } auto c = TRY(stream.read_value()); bytes_to_read--;