Commit Graph
2706 Commits
Author SHA1 Message Date
Acts1631andGitHub 2ada48a77f ASF: limit header object count (#1395)
ASF header parsing retained an unbounded number of objects. A crafted
file with many small objects could consume disproportionate memory.

Reject files whose header object count exceeds the parser limit.
2026-08-03 18:46:01 +02:00
Acts1631andGitHub a1d0488dc6 RIFF: limit parsed chunk count (#1394)
RIFF files could contain an unbounded number of small chunks. The
parser retained a descriptor for each chunk, allowing a crafted file
to consume disproportionate memory.

Reject files that exceed a maximum parsed chunk count.
2026-08-03 18:35:36 +02:00
Acts1631andGitHub af2010ff39 Matroska: limit elements in EBML containers (#1393)
EBML containers could contain an unbounded number of small elements.
The parser retained each element, allowing a crafted Matroska file to
consume disproportionate memory.

Reject containers that exceed a per-level element count limit.
2026-08-03 18:30:51 +02:00
Acts1631andGitHub c0f2a939b4 MP4: limit atoms in nested containers (#1392)
Nested MP4 containers did not enforce the atom count limit applied at
the root level. A small file with many child atoms could consume
disproportionate memory while building the atom tree.

Apply the per-level limit to container children and reject files that
exceed it.
2026-08-03 17:46:53 +02:00
Acts1631andGitHub cb92e0aec4 MPC: validate SV8 packet size (#1391)
SV8 packet parsing subtracted its header size from an unchecked
unsigned packet length. An undersized value could wrap and make the
parser allocate the remainder of a large file.

Reject packet lengths smaller than their header or beyond the remaining
file data before reading the payload.
2026-08-03 15:46:46 +02:00
Acts1631andGitHub fd97c86bcb MP4: reject undersized table atoms (#1390)
MP4 chapter parsing subtracted table headers from atom lengths without
checking that the headers were present. A short atom could wrap the
read length and allocate the remainder of a large file.

Validate table sizes before reading their payloads and before updating
chunk offsets while saving.
2026-08-02 16:47:17 +02:00
Acts1631andGitHub 04993427d7 Bound ASF attribute parsing to object data (#1389)
A truncated ASF attribute object could declare a large count and make
the parser create empty attributes after reaching the end of its data.

Validate each attribute object's data extent and stop parsing when an
attribute would exceed it.
2026-08-02 08:23:08 +02:00
Acts1631andGitHub 586a658650 Prevent DSDIFF chunk size wrap (#1388)
A crafted DSDIFF chunk size could wrap the parser boundary check,
seek backwards, and make the parser loop indefinitely.

Compare chunk sizes with remaining bytes before seeking at each DSDIFF
chunk nesting level.
2026-08-02 08:14:43 +02:00
Thomas BergwinklandGitHub 5530420d08 Fix ID3v2 frame data length check for per-frame unsynchronised ID3v2.4 frames (#1385)
Frame::fieldData() (taglib/mpeg/id3v2/id3v2frame.cpp) discarded any
ID3v2.4 frame whose declared size (from the header) no longer matched
its actual buffer size after per-frame unsynchronisation was decoded by
FrameFactory::prepareFrameHeader(), silently emptying frames like
TIT2/TPE1/TALB. Clamp the declared length to what's actually available
instead of discarding the frame, only bailing out if the frame's data
offset itself doesn't fit.

Adds testUnsynchDecodeID3v24Frame() to tests/test_id3v2.cpp, covering a
frame with its own per-frame Unsynchronisation flag (as opposed to the
tag-wide flag already covered by testUnsynchDecode()), using new fixture
tests/data/unsynch24.id3.
2026-08-01 07:53:53 +02:00
MSOB7YandGitHub a100d0b2ec MP4: Allow extracting covr with wrong flags (#1383)
If the covr has invalid flags, detect the image format from the magic bytes
and return the image anyways even if the type is unknown.
2026-08-01 07:32:43 +02:00
Urs FleischandGitHub e8f1e058d6 Use Requires.private for zlib with pkg-config (#1380)
Express dependency on zlib using Requires.private in pkg-config .pc
file instead of adding -lz to the libs.

This will cause the following changes when using TagLib with
pkg-config:
- When using a dynamic library, -lz will no longer be present in
  in linker command, but being linked transitively.
- When using a static library, pkg-config must be used with the
  --static command line argument, then libs will still contain
  -lz, which is needed when linking statically.
- The flags needed for zlib will be provided by pkg-config,
  so if -lz is not appropriate (e.g. with MSVC), correct
  linker flags will be provided.
2026-08-01 06:19:41 +02:00
Acts1631andGitHub 18572e90a6 Limit ID3 compressed-frame expansion (#1382)
A crafted compressed ID3v2 frame can declare an excessive output size
and cause zlib to allocate memory based on attacker-controlled data.

Bound decompression by an absolute 64 MiB limit and a 64:1 expansion
ratio, while retaining normal ID3v2.3 length handling.
2026-08-01 06:18:24 +02:00
Acts1631andGitHub 3aa04e3be4 Fix Shorten AIFF chunk offset wrap (#1381)
A crafted embedded AIFF chunk size could wrap the parser offset and
make it repeatedly process the same chunk, causing a denial of service.

Validate AIFF chunk headers and padded sizes against the remaining
verbatim-header data, and advance every parsed chunk to its checked end.
2026-08-01 06:12:47 +02:00
Urs Fleisch 54ae7d8ac4 Version 2.3.1
Pin submodule utfcpp to tag v4.1.1.
v2.3.1
2026-07-19 19:58:28 +02:00
f7c28ac742 MP4: Fix QT chapters excessive sample allocation with invalid stsc (#1379)
See https://mail.kde.org/pipermail/taglib-devel/2026-July/003122.html

---------

Co-authored-by: Lee, Brian J <[email protected]>
2026-07-17 05:22:50 +02:00
Urs Fleisch 93ebb7fb79 Prepare 2.3.1 release 2026-07-12 20:16:12 +02:00
Urs Fleisch f09a84c4ae Enlarge MP4 atom sibling count at top level limit (#1344)
The MAX_MP4_ATOM_COUNT_PER_LEVEL of 5000 seems to be too restrictive,
a legitimate file with 5390 atoms was reported to have been rejected.
The crafted file from #1344 had 653789 atoms at the top level, which
freezed the read process for 15s on my system. Enlarging the limit
to 50000 should be sufficient and will stop the crafted file after 2s.
2026-07-11 09:05:17 +02:00
Urs FleischandGitHub 834bf0622f Fix seeking next atom after stem with 64-bit length (#1363) (#1378) 2026-07-11 09:03:18 +02:00
eb698de6e5 [Matroska] Fix unknown size elements (#1377)
In matroska an element data size of a VINT with all bits 1 means the
data size is unknown. Unknown data size can only apply to Master
Elements.

Unknown sized elements are described in
https://datatracker.ietf.org/doc/rfc8794/ section 6.2
It gives the following 5 conditions for detecting the end of an
unknown sized element:

 *  Any EBML Element that is a valid Parent Element of the Unknown-
    Sized Element according to the EBML Schema, Global Elements
    excluded.

 *  Any valid EBML Element according to the EBML Schema, Global
    Elements excluded, that is not a Descendant Element of the
    Unknown-Sized Element but shares a common direct parent, such as a
    Top-Level Element.

 *  Any EBML Element that is a valid Root Element according to the
    EBML Schema, Global Elements excluded.

 *  The end of the Parent Element with a known size has been reached.

 *  The end of the EBML Document, either when reaching the end of the
    file or because a new EBML Header started.

In this patch we use the higher level maxOffset to determine
the maximum data size for the element, which matches the fourth
condition, but is incomplete without the other four methods.

As only Segment and Cluster elements of Matroska files are allowed
to use unknown size length and TagLib does not process Cluster
elements, this should be sufficient.

---------

Signed-off-by: Anthony Brandon <[email protected]>
Co-authored-by: Urs Fleisch <[email protected]>
2026-07-11 09:02:39 +02:00
Anthony BrandonandUrs Fleisch e0d24f7fa7 [Matroska] Skip invalid Elements
Some files might have some invalid elements, but most elements might be
correct. In this case it would be useful to still parse the correct
elements and skip the invalid ones.

When an invalid element is encountered we can set the seek position in
the file to the (known) end of that Element. Then further elements can
be read starting from that position.

Signed-off-by: Anthony Brandon <[email protected]>
2026-07-05 10:53:55 +02:00
Anthony BrandonandUrs Fleisch 13239fde26 [Matroska] Check element length before constructing
By checking the Element size against the maximum offset we can find
out of bounds elements early and not try to read them at all.
This is useful for the next patch.

Signed-off-by: Anthony Brandon <[email protected]>
2026-07-05 10:53:55 +02:00
Anthony BrandonandUrs Fleisch 2185b47d5f [Matroska] Clear size listeners before adding
Each time save is called registerSizeListener will add
new size listeners. If save is called multiple times this causes the
same delta being add/subtracted multiple times, resulting in incorrect
element sizes.

This can be observed in TestMatroska::testRepeatedSave.
Although the test passes, some sizes are incorrect resulting in the
following messages being printed during the test:

  TagLib: Failed to read VINT size
  TagLib: Failed to parse EMBL ElementID

Signed-off-by: Anthony Brandon <[email protected]>
2026-07-05 10:53:55 +02:00
Urs FleischandGitHub e589efd0da Matroska: Fix crash when seek head invalid or missing (#1375)
Also be more tolerant when parsing the seek head:
- accept elements with offset 0,
- skip invalid elements.
2026-06-27 07:09:33 +02:00
EvilGivenandGitHub 860406eb98 Fix XM save path to skip sample data after sample headers (#1369)
XM saving failed for files with samples because the save logic only
advanced past sample headers and did not skip the sample data, causing
the next instrument to be written at the wrong position.
2026-06-26 21:28:50 +02:00
Urs FleischandGitHub fa189f6cf7 Fix data length indicator check for compressed ID3v2 frames (#1371) 2026-06-26 09:39:27 +02:00
e958fa0bfa Fix overflow for large Apple Music cnID values (#1373)
cnID must be longlong instead of int as Apple Music cnID values can now
exceed the range of a 32-bit integer and require 64-bit aka longlong.

---------

Co-authored-by: Urs Fleisch <[email protected]>
2026-06-26 07:12:16 +02:00
dependabot[bot]andUrs Fleisch b42db0ea78 Bump actions/checkout from 6 to 7
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
2026-06-24 05:27:17 +02:00
HomerJauandUrs Fleisch a27dca557e [Matroska] Allow Chapters Without a ChapterUID
Fix: Don't silently drop ChapterAtom elements that omit MkChapterUID

parseChapterAtom() returned chapterUid = 0 when the source file omitted
the MkChapterUID element, and the existing call sites in
MkChapters::parse() (ebmlmkchapters.cpp lines 106 and 127) use a C++17
init-if `chapter.uid()` predicate that silently dropped such chapters.
The caller saw an empty ChapterEditionList for files that mkvinfo,
MediaInfo and FFmpeg all handle gracefully — produced by some audiobook
generators and older muxers that omit the per-chapter UID. The
companion orphan-EditionEntry fix in PR #1311 / commit e07b956f doesn't
cover this case because the ChapterAtoms there ARE wrapped in an
EditionEntry, just without a ChapterUID inside each atom.

This change:
- Synthesises a process-unique ChapterUID inside parseChapterAtom() when
  the source file lacks MkChapterUID. The synthetic value sets the high
  bit (1ULL << 63) and increments via a static std::atomic counter; real
  ChapterUIDs are random 64-bit values from muxers, so collision with a
  generated one is practically impossible while keeping the distinction
  local to TagLib.
- The existing chapter.uid() filters at the call sites then always
  evaluate truthy and the chapter is exposed through the public
  ChapterEditionList API as if it were spec-compliant.

No existing behavior is changed — files that already conform to the spec
(ChapterAtoms with a ChapterUID element) parse identically; only
previously-dropped chapters are now surfaced.

Reported and verified against real-world chaptered Matroska audiobook
files where mkvinfo / MediaInfo see all chapters but TagLib 2.3 returned
an empty ChapterEditionList.
2026-05-19 21:32:40 +02:00
Ryan FrancesconiandUrs Fleisch 8fcda2daa2 [FLAC] Pack hasiXML/hasBEXT with scanned to save padding
Per review feedback on #1364: moving the two new bool flags to the end
of FilePrivate, next to the existing `scanned` bool, lets the compiler
coalesce the three bytes into the same trailing padding slot.  Saves one
machine word per FLAC::File instance versus placing the flags mid-struct
between bextData and the List<MetadataBlock*>.

Pure layout change, no behaviour difference.  Test suite still green.
2026-05-17 16:38:07 +02:00
Ryan FrancesconiandUrs Fleisch c32f7c7f86 [FLAC] Track iXML/BEXT block presence with explicit flags
hasiXMLData() / hasBEXTData() were implemented as !data.isEmpty()
checks, which conflated in-memory payload with on-disk block presence.
That caused two wrong answers:

* setiXMLData("foo") on a file with no iXML block made hasiXMLData()
  return true immediately, before save().
* A FLAC file carrying an iXML APPLICATION block with empty payload
  round-tripped fine, but hasiXMLData() reported false.

Switch to the same model RIFF::WAV::File already uses: explicit
hasiXML / hasBEXT bool flags on FilePrivate, set during scan() when
the APPLICATION block is recognised, updated during save() after the
block is (re)written or omitted, and returned verbatim by the
accessors. New regression test pins down the before/after-save and
empty-block cases.

Refs: https://github.com/taglib/taglib/issues/1362
2026-05-17 16:38:07 +02:00
Stephen BoothandUrs Fleisch e23d97c580 Add algorithm include for std::min and max 2026-05-17 08:18:58 +02:00
Stephen BoothandUrs Fleisch b8b91fd072 Add algorithm include for std::find_if 2026-05-17 08:18:58 +02:00
Stephen BoothandUrs Fleisch e83e02da2e Correct documentation comment for timeEnd 2026-05-17 08:16:07 +02:00
Stephen BoothandUrs Fleisch 0b5296e20e Correct assignment operator qualification 2026-05-17 08:13:48 +02:00
Stephen BoothandUrs Fleisch 83fdf27cd7 Correct assignment operator qualification 2026-05-17 08:13:48 +02:00
Stephen BoothandUrs Fleisch 7010d112ba Correct destructor qualification 2026-05-17 08:12:12 +02:00
Urs Fleisch 1b94b93762 Version 2.3 v2.3 2026-05-10 15:25:51 +02:00
HomerJauandUrs Fleisch 8511827fa1 Skip Matroska Cues with AudioProperties::Fast and read-only mode
When the file is opened in read-only mode, it will not be written and
the Cues do not have to be updated. Skipping the Cues will make the
reading of large Matroska files over network filesystems (SMB/NFS)
faster.
2026-05-09 09:25:14 +02:00
Urs Fleisch b02ff63916 Fix -Wconversion size_t to unsigned int warning 2026-05-09 08:28:54 +02:00
HomerJauandUrs Fleisch f1e8dac084 [Matroska: Follow chained SeekHead entries when parsing segment metadata
Some muxers — notably MakeMKV, and mkvmerge in certain configurations — write a small primary seekHead at the start of the segment that contains a single entry referencing a secondary seekHead near the end of the file. The secondary seekHead carries the actual entries for info, tracks, tags, chapters, and attachments.
2026-05-08 05:17:23 +02:00
Luc SchrijversandUrs Fleisch d1460b6fbf Build fix for Haiku's fcntl.h which can't be found in sys/fcntl.h 2026-05-07 18:32:19 +02:00
Urs Fleisch 43190d30ed Prepare 2.3 release 2026-05-04 13:02:17 +02:00
4c43f1c577 Matroska: Provide different WriteStyle to trade-off size/speed
A new Matroska::File::save(WriteStyle style) overload is provided to
control how tags, attachments and chapters are written to the file.

- Compact: Write tags, attachments and chapters as compact as possible.
  This is the default mode.
- DoNotShrink: Do not shrink elements; add void padding when content
  gets smaller. Allow inserts when content gets larger.
- AvoidInsert: Like DoNotShrink but also avoid inserts for non-last
  elements: replace a growing non-last element with a void of the old
  size and append the new element at the end of the segment.
  For very large files and/or slow (network) filesystems, using this
  mode will reduce write time significantly.

Co-authored-by: Copilot <[email protected]>
2026-05-04 12:55:17 +02:00
Ryan FrancesconiandUrs Fleisch 59ed19d12f [WAV] Decode iXML as UTF-8
The iXML chunk in BWF/WAV files is specified as UTF-8 (per the EBU
Tech 3285 supplement and the iXML spec). The reader was constructing
the String without an encoding hint, which falls back to Latin-1 and
mangles any non-ASCII bytes (e.g. Unicode in <NOTE>, <PROJECT>, or
<TRACK_LIST> entries written by Sound Devices, Zaxcom, etc.).
2026-05-01 06:32:09 +02:00
Ryan FrancesconiandUrs Fleisch 1e7bdae284 [FLAC] Add iXML and BEXT support via APPLICATION blocks
Adds 6 public methods on FLAC::File mirroring RIFF::WAV::File's existing
iXML/BEXT API: iXMLData/setiXMLData/hasiXMLData and the BEXT equivalents.

Reads APPLICATION blocks (RFC 9639 § 8.4) carrying either the IANA-
registered "riff" foreign-metadata wrapper or the direct "iXML" / "bext"
application IDs used by some third-party tools (e.g. Sequoia). Writes
the spec-blessed "riff"-wrapped form. Unrecognized application IDs and
"riff"-wrapped chunks other than iXML/bext (e.g. "fmt ", "JUNK") flow
through unmodified, so existing files round-trip without churn.

Test coverage: read direct + riff-wrapped for both iXML and BEXT,
write+reread round-trip, empty-clears-block, and an unknown-application-
block preservation guard.
2026-05-01 06:31:50 +02:00
HomerJauandUrs Fleisch e07b956fda [Matroska] Allow Orphaned Chapter Reading (when Chapter has no EditionID)
Fix: Handle orphan ChapterAtom elements not wrapped in EditionEntry

The Matroska specification requires every ChapterAtom to be inside an
EditionEntry. However, some muxers (older FFmpeg versions, some streaming
tools) produce files with ChapterAtom elements directly under Chapters,
without an EditionEntry wrapper.
MKVToolNix and FFmpeg both handle this case gracefully by treating orphan
atoms as belonging to an implicit default edition. Previously, TagLib
silently ignored these chapters, returning an empty ChapterEditionList.

This change:
- Collects orphan ChapterAtom elements encountered directly under Chapters
- Wraps them in an implicit default edition (UID = 0, isDefault = true,
  isOrdered = false) so they are exposed through the existing
  chapterEditionList() API
- Extracts the atom-parsing logic into a private parseChapterAtom() helper
  to avoid code duplication between the two call sites

No existing behavior is changed - files that already conform to the spec
(chapters inside an EditionEntry) parse identically.
2026-04-26 08:24:19 +02:00
Urs Fleisch 5e1cb4081d Limit MP4 atom sibling count at top level (#1344) 2026-04-26 07:16:53 +02:00
Urs FleischandGitHub e7e4f0958c Merge pull requests #1325 #1343 from ryanfrancesconi MP4 chapterlist
ryanfrancesconi/feature/mp4-chapterlist
ryanfrancesconi/fix/qt-chapter-orphaned-mdat
2026-04-26 07:15:40 +02:00
Urs Fleisch 497c040f04 Set MP4 chapters only if modified
An equality operator is added for the chapters. The chapters are
only written to the file if they were really modified, so just
reading the chapters without modifying them will not affect
the save operation.
2026-04-25 11:46:51 +02:00
Ryan Francesconi 05c2c8671e MP4: Add test coverage for chapter unicode, empty titles, and format independence
Six new tests exercise corners of the chapter implementation that the
orphaned-mdat fix did not reach:

testQTChapterListUnicodeTitles / testChapterListUnicodeTitles --
Round-trip Japanese, German (umlaut), and Russian titles through the
QT text-sample serialisation and the Nero length-prefixed UTF-8 path
respectively.  These are separate paths in the code and benefit from
separate coverage.

testQTChapterListEmptyTitleStripped --
A multi-chapter list whose first entry is empty at t=0 matches the QT
dummy-marker pattern; read() must drop it.  Test documents the rule so
a regression is immediately detectable.

testQTChapterListSingleEmptyTitleNotStripped --
The stripping rule only applies when size > 1.  A single empty-title
chapter at t=0 is valid and must be preserved.

testNeroAndQTChaptersAreIndependent --
Both formats can coexist; removing one leaves the other intact.
Validates the lazy saveChaptersIfModified contract in mp4file.cpp.

testNeroChaptersAloneWhenNoQT --
Writing one format must not create atoms for the other.

All 47 MP4 tests pass.
2026-04-23 12:19:27 -07:00