Skip to content
Memory corruption Advisory Advanced CVE-2022-25942

HDF5 Group libhdf5 gif2h5 out-of-bounds read vulnerability

The gif2h5 conversion tool in libhdf5 1.10.4 does not check the actual file length against the global colour table size declared in a GIF header, so a short crafted GIF makes the palette-reading loop run past the end of the file buffer. The pointer then lands inside the tool's own header structure, whose bytes are parsed as image data, which can corrupt the heap and, per the report, lead to code execution.

Dave McDaniel Follow

Originally disclosed on Cisco Talos

High 7.8 View original

An out-of-bounds read vulnerability exists in the gif2h5 functionality of HDF5 Group libhdf5 1.10.4. A specially-crafted GIF file can lead to code execution.

Dave McDaniel, on Cisco Talos

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the palette-reading loop in ReadGifHeader() trusts the table size taken from the GIF header and never verifies that the input buffer actually contains that many bytes, so the read pointer advances past the end of the file data.

Impact

A crafted GIF could cause heap corruption and, as the report claims, code execution, though the demonstrated outcome is a crash from freeing an attacker-influenced pointer.

What the attacker needed

Attacker supplies a crafted GIF file; victim runs gif2h5 on the file

How it was found

  1. Craft a GIF whose header declares the maximum global colour table size while the file itself is much shorter.
  2. Run the gif2h5 conversion on that file so ReadGifHeader() is called.
  3. Observe the palette loop reading past the end of the file buffer and into the GifHead structure.
  4. Watch the returned pointer now point inside GifHead, so the image-parsing loop interprets header bytes as image data.
  5. See the image array reallocation shift a pointer into the palette data, and freeing that pointer crash the program.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A GIF file starts with a header that says how many colours its palette holds. The converter trusts that number and keeps reading colour bytes even after the file has ended, so it reads whatever memory comes next. Because that memory belongs to the program's own data structures, the program then treats its own bookkeeping as image content, which can crash it or let an attacker steer it.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Dave McDaniel

View all

23 more disclosed reports, best first.

More from Cisco Talos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.