Skip to content

ByteVector, List: Check indices if the standard library does - #1467

Merged
ufleisch merged 1 commit into
taglib:masterfrom
vera-rubin:fix/bytevector-list-index-checks
Oct 31, 2026
Merged

ufleisch merged 1 commit into
taglib:masterfrom
vera-rubin:fix/bytevector-list-index-checks

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

With _GLIBCXX_ASSERTIONS or a libc++ hardening mode, std::vector::operator[] is bounds-checked, but ByteVector::operator[] and List::operator[] are not. A ByteVector from mid() shares its parent's buffer, so std::vector accepts an index past the end of the smaller vector. List::operator[] walks a std::list, which these checks don't cover.

In those builds, both operators now check against their own size and abort, which makes them harder to misuse. Other builds are unchanged: a GCC Release libtag.so has identical code.

The Ubuntu CI job now builds with -D_GLIBCXX_ASSERTIONS. A new test covers indexing mid() results.

If it lands, we may submit it to Google's Patch Rewards program, and we'd be glad to share any reward with the maintainers.

— ChipLab

If the standard library checks the index in std::vector::operator[]
(_GLIBCXX_ASSERTIONS, libc++ hardening modes), ByteVector::operator[]
and List::operator[] now check the index against their own size and
abort if it is out of range, as std::vector does.

The std::vector check alone is not enough: a ByteVector created by
mid() shares the buffer of the original byte vector, so an index past
the end of the smaller vector still passes it. List::operator[] walks
a std::list, which these checks do not cover.

Builds without these macros are unchanged; a GCC Release build of
libtag produces identical code. The Ubuntu CI job now builds with
-D_GLIBCXX_ASSERTIONS so that the tests run with the checks enabled.
@ufleisch
ufleisch merged commit 50ca520 into taglib:master Oct 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants