diff --git a/Libraries/LibCompress/Lzw.h b/Libraries/LibCompress/Lzw.h index b0fa8793fe9..201450baa5d 100644 --- a/Libraries/LibCompress/Lzw.h +++ b/Libraries/LibCompress/Lzw.h @@ -109,7 +109,15 @@ public: u16 const end_of_data_code = lzw_decompressor.add_control_code(); while (true) { - auto const code = TRY(lzw_decompressor.next_code()); + // Some encoders omit the End-of-Information code or emit trailing padding that decodes as invalid LZW + // codes. Treat any LZW error as an implicit end of the compressed stream and use whatever was successfully + // decoded so far - this matches the behavior of Firefox, Chrome and Safari. + auto code_or_error = lzw_decompressor.next_code(); + if (code_or_error.is_error()) { + dbgln_if(LZW_DEBUG, "LZW stream ended unexpectedly: {}", code_or_error.release_error()); + break; + } + auto const code = code_or_error.release_value(); if (code == clear_code) { lzw_decompressor.reset(); diff --git a/Tests/LibWeb/Layout/expected/table-replaced-child-percentage-height-in-auto-table.txt b/Tests/LibWeb/Layout/expected/table-replaced-child-percentage-height-in-auto-table.txt index cf7969c29fd..ffa541a765e 100644 --- a/Tests/LibWeb/Layout/expected/table-replaced-child-percentage-height-in-auto-table.txt +++ b/Tests/LibWeb/Layout/expected/table-replaced-child-percentage-height-in-auto-table.txt @@ -1,21 +1,21 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline BlockContainer at [0,0] [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline - TableWrapper <(anonymous)> at [8,8] positioned [8+0+0 0 0+0+8] [8+0+0 0 0+0+8] [BFC] children: not-inline - Box
at [8,8] table-box [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [TFC] children: not-inline - Box <(anonymous)> at [8,8] table-row [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] children: not-inline - BlockContainer <(anonymous)> at [8,8] table-cell [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline - ImageBox
+
+
+
diff --git a/Tests/LibWeb/Ref/input/wpt-import/gif/reset-no-gce.gif b/Tests/LibWeb/Ref/input/wpt-import/gif/reset-no-gce.gif
new file mode 100644
index 00000000000..98e6bc61ac4
Binary files /dev/null and b/Tests/LibWeb/Ref/input/wpt-import/gif/reset-no-gce.gif differ
diff --git a/Tests/LibWeb/Text/expected/HTML/lzw-image-without-EOI-should-still-load.txt b/Tests/LibWeb/Text/expected/HTML/lzw-image-without-EOI-should-still-load.txt
new file mode 100644
index 00000000000..ae6ab609aa5
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/lzw-image-without-EOI-should-still-load.txt
@@ -0,0 +1,2 @@
+GIF: loaded, width=1, height=1
+TIFF: loaded, width=1, height=1
diff --git a/Tests/LibWeb/Text/input/HTML/lzw-image-without-EOI-should-still-load.html b/Tests/LibWeb/Text/input/HTML/lzw-image-without-EOI-should-still-load.html
new file mode 100644
index 00000000000..6d667d0b737
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/lzw-image-without-EOI-should-still-load.html
@@ -0,0 +1,25 @@
+
+
+