Skip to content
Memory corruption Write-up Advanced

When -1 Crossed a Library Boundary: How libvips Hardened Its TIFF Loader

A libvips TIFF read callback returned -1 to signal a read error, but libtiff's client read handler does not support negative return values, so the value could reach a vulnerable libtiff function and contribute to a heap out-of-bounds write. An attacker able to trigger a failed source read during TIFF strip loading could reach that memory-corruption path in vulnerable libtiff builds.

aleens09 Follow

Published on medium.com

In libvips, -1 meant that a read had failed. In the libtiff callback receiving that value, however, a negative result was not a supported error signal.

Aleens-labs, on medium.com

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 write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a contract mismatch: libvips signalled a read failure with a negative return value that libtiff's read callback does not support, and the vulnerable libtiff revision updated its byte counter before rejecting the negative result.

Impact

The confirmed impact is a heap out-of-bounds write and possible process corruption in the vulnerable libtiff path; the text states that remote code execution, information disclosure and even universal denial of service through libvips were not demonstrated.

What the attacker needed

A failed read during TIFF strip loading; libvips linked to a vulnerable libtiff build

The fix

libtiff was fixed upstream to validate negative read results before updating state, and libvips was fixed so its callback treats both EOF and read errors as a zero-byte result instead of returning a negative value.

How it was found

  1. Build a pre-fix libvips revision with AddressSanitizer and link it to the vulnerable libtiff revision used for the original test.
  2. Use a controlled VipsSource whose read operation fails during TIFF strip loading.
  3. Confirm that the old openin_source_read() path can return -1 to libtiff.
  4. Repeat with libvips commit 8591369 or the merged commit 10db2ed.
  5. Confirm that bytes_read <= 0 stops the read loop and the callback returns a non-negative byte count.
  6. Independently test the patched libtiff revision and confirm that negative read results are rejected before updating already_read.

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 write-up has not been written yet. The Original tab links to the source.

When one program hands data to another, they must agree on what each value means. Here libvips used the number -1 to say 'the read failed', but the TIFF library expected only counts of bytes read and did not handle a negative number safely. That negative number could then be used in a size calculation, causing the library to write one byte outside a memory buffer.

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 aleens09

View all

3 more disclosed reports, best first.

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.