diff options
author | Peter Nelson <peter@peterdn.com> | 2020-12-28 12:31:09 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-28 15:12:29 +0100 |
commit | 476911e1f90742c4bf67e9b3d1815c8211f40bdd (patch) | |
tree | 5e717700177a22209db41d422ce71d40f1da0ca6 | |
parent | be30dc2b18621d8932a4122b22af692e1f9139f5 (diff) | |
download | serenity-476911e1f90742c4bf67e9b3d1815c8211f40bdd.zip |
LibGfx: fix OOB access in LZW decoder on bad input
This fixes an issue where a corrupted LZW code can result in the first
element of an empty buffer being accessed.
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27863
-rw-r--r-- | Libraries/LibGfx/GIFLoader.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Libraries/LibGfx/GIFLoader.cpp b/Libraries/LibGfx/GIFLoader.cpp index d50bd73a60..7a0480379d 100644 --- a/Libraries/LibGfx/GIFLoader.cpp +++ b/Libraries/LibGfx/GIFLoader.cpp @@ -218,6 +218,12 @@ public: << m_current_bit_index << ", code table size: " << m_code_table.size(); #endif return {}; + } else if (m_current_code == m_code_table.size() && m_output.is_empty()) { +#ifdef GIF_DEBUG + dbg() << "Corrupted LZW stream, valid new code but output buffer is empty: " << m_current_code + << " at bit index: " << m_current_bit_index << ", code table size: " << m_code_table.size(); +#endif + return {}; } m_current_bit_index += m_code_size; @@ -234,6 +240,7 @@ public: new_entry.append(m_output[0]); extend_code_table(new_entry); } else if (m_current_code == m_code_table.size()) { + ASSERT(!m_output.is_empty()); m_output.append(m_output[0]); extend_code_table(m_output); } |