[Pkg-kde-extras] Bug#1154148: exiv2: reading QuickTime/MP4 metadata allocates a buffer the size of the whole video (fixed upstream in 0.28.9)
Emmanuel Revah
bugreport at manurevah.com
Mon Nov 16 10:53:14 GMT 2026
Source: exiv2
Version: 0.28.5+dfsg-1
Severity: important
Tags: patch fixed-upstream trixie
Dear Maintainer,
In trixie, reading the metadata of a QuickTime/MP4 video with libexiv2
allocates (and zero-fills) a buffer as large as the video itself. A
phone
video of 8.46 GB makes any program that reads its metadata take ~8 GB of
RAM
for a few seconds, which on a 16 GB desktop means heavy swapping and a
frozen application.
How I hit it: Gwenview, with a photo folder sorted by date. To sort,
Gwenview reads the date of every file through libexiv2, videos included,
on its GUI thread. Opening any photo in a camera folder that contains
one
large video made Gwenview grow to 8.2-8.5 GB within seconds, freeze, and
end up killed via KWin's "not responding" dialog.
Cause
-----
src/quicktimevideo.cpp, QuickTimeVideo::decodeBlock(): after reading a
box
header, the 5-byte tag buffer is resized to the full box size
const auto newsize = static_cast<size_t>(size - hdrsize);
if (newsize > buf.size()) {
buf.resize(newsize);
}
tagDecoder(buf, newsize, recursion_depth + 1);
before tagDecoder() looks at the tag. For "mdat" (the media data, i.e.
almost the whole file) tagDecoder() only calls discard(size), a seek.
The
buffer is never used beyond its first 4 bytes, but resize() has already
allocated and zero-filled it.
Upstream removed the resize in 0.28.9 (and main):
https://github.com/Exiv2/exiv2/commit/40be751eda (0.28.x, "Remove
unnecessary resize")
https://github.com/Exiv2/exiv2/commit/1a1f0ab960 (main)
forky and sid have 0.28.9+dfsg-1 and are fixed. Only trixie is affected.
The memory is bounded by the file size (decodeBlock() enforces that a
box
fits in the remaining file), so this is not a crafted-file issue; it
hits
ordinary large videos.
Reproduce (plain trixie)
------------------------
exiv2 -q -pa some-large-video.mp4
and look at the maximum RSS (e.g. /usr/bin/time -v, or getrusage).
Measured here, with the exiv2 0.28.5+dfsg-1 command line tool:
- 8.46 GB .mp4, stock libexiv2-28 0.28.5+dfsg-1: max RSS 6.6 GB, 4.1 s
(the rest was pushed to swap)
- same file, libexiv2-28 rebuilt with the attached patch: max RSS 11 MB,
0.1 s
- 0.68 GB .mp4, stock: 657 MB; patched: 11 MB
In Gwenview (4:25.04.3-1), same folder, the A/B gave 7.3 GB peak + 676
MB
swap with the stock library, 120 MB with the patched one.
Patch
-----
The attached patch is the upstream commit, unchanged apart from the
DEP-3
header; it applies to 0.28.5+dfsg-1 with a 1-line offset. In 0.28.5,
tagDecoder() only ever reads 4 bytes into this buffer, so removing the
resize is safe on its own. I rebuilt the Debian package with it
(0.28.5+dfsg-1 + this patch only): the package test suite passes (100%,
6/6 ctest groups).
Request
-------
Please consider the attached patch for a trixie stable update.
-- System Information:
Debian Release: 13 (trixie)
Kernel: Linux 6.12.116+deb13-amd64
Versions: libexiv2-28 0.28.5+dfsg-1, gwenview 4:25.04.3-1
--
Emmanuel Revah
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exiv2_40be751eda_quicktime-remove-unnecessary-resize.patch
Type: text/x-diff
Size: 966 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-kde-extras/attachments/20261116/77ad4687/attachment.patch>
More information about the pkg-kde-extras
mailing list