VYPR
Unrated severityNVD Advisory· Published Mar 9, 2022· Updated Aug 2, 2024

CVE-2022-0891

CVE-2022-0891

Description

A heap buffer overflow in ExtractImageSection function in tiffcrop.c in libtiff library Version 4.3.0 allows attacker to trigger unsafe or out of bounds memory access via crafted TIFF image file which could result into application crash, potential information disclosure or any other context-dependent impact

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

Affected products

36

Patches

Vulnerability mechanics

Root cause

"Incorrect offset and size calculations in `extractImageSection` that omit the `spp` (samples per pixel) multiplier, combined with a use-after-free from `rotateImage`, cause out-of-bounds heap reads."

Attack vector

An attacker supplies a crafted TIFF image with malformed tags (e.g., missing `StripByteCounts`, invalid `PageNumber` count) and specific crop/rotate parameters (`-E l -H 10 -V 10 -S 8:4 -R 270`). When `tiffcrop` processes the image, `rotateImage` allocates a buffer, then frees it, and `extractImageSection` subsequently reads from the freed buffer (heap-use-after-free at line 6866) [ref_id=2]. The incorrect offset calculations in `extractImageSection` also cause heap buffer overflows by reading beyond the allocated region [ref_id=1].

Affected code

The vulnerability resides in `extractImageSection` in `tools/tiffcrop.c` (line 6866). The function computes buffer offsets using `shift2` and `offset2` variables that were removed in the patch; the old code used `offset2` (derived from `last_col * bps / 8`) without accounting for `spp`, leading to out-of-bounds reads. The patch also corrects the `img_rowsize` calculation and the `sectsize` computation in `writeImageSections` (line 7091) to multiply by `spp` before dividing by 8 [ref_id=1].

What the fix does

The patch removes the `shift2` and `offset2` variables and corrects all offset calculations to multiply by `spp` before dividing by 8, ensuring proper byte alignment for multi-sample pixels [ref_id=1]. It also fixes `img_rowsize` to `((img_width * spp * bps) + 7) / 8` and `full_bytes` to `(sect_width * spp * bps) / 8`, and corrects `sectsize` in `writeImageSections` to `ceil((width * bps * spp + 7) / 8.0) * length`. These changes prevent out-of-bounds reads and writes by computing accurate buffer sizes and offsets.

Preconditions

  • inputAttacker must provide a crafted TIFF file that triggers the heap-use-after-free condition when processed by tiffcrop.
  • inputThe tiffcrop tool must be invoked with crop/rotate flags such as '-E l -H 10 -V 10 -S 8:4 -R 270' to reach the vulnerable code path.

Reproduction

Clone libtiff source, compile with AddressSanitizer (`-fsanitize=address,undefined`), then run: `./tiffcrop -i -E l -H 10 -V 10 -S 8:4 -R 270 poc.tif a.tif` [ref_id=2]. The ASAN log confirms a heap-use-after-free read at `extractImageSection` line 6866, with the freed region originating from `rotateImage` at line 8697 [ref_id=2].

Generated on May 24, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

9

News mentions

0

No linked articles in our index yet.