Browse Source

LibGfx: Don't read past EOF in JPEGLoader

Previously, it was possible to pass JPEGLoader a crafted input which
would read past the end of the stream. We now return an error in such
cases.
Tim Ledbetter 1 year ago
parent
commit
dd81bea9ef
1 changed files with 3 additions and 0 deletions
  1. 3 0
      Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp

+ 3 - 0
Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp

@@ -230,6 +230,9 @@ private:
         VERIFY(m_byte_offset == m_current_size);
 
         m_current_size = TRY(m_stream->read_some(m_buffer.span())).size();
+        if (m_current_size == 0)
+            return Error::from_string_literal("Unexpected end of file");
+
         m_byte_offset = 0;
 
         return {};