Skip to content

Harden constant metadata tag tables (follow-up to #265) - #271

Merged
danoli3 merged 4 commits into
masterfrom
taglib/harden-constant-tables
Nov 9, 2026
Merged

danoli3 merged 4 commits into
masterfrom
taglib/harden-constant-tables

Conversation

@danoli3

@danoli3 danoli3 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Stacked on #265: the first three commits are that PR, so this will shrink to a single commit once #265 lands. Review only Harden constant metadata tag tables.

Follow-ups from review of #265:

  1. Sort order outside tests. Binary search needs strictly increasing tag IDs. Debug builds now check every table once on first TagLib::instance(); TagLibTest calls the same check. Swapping two rows in TagLibData.h makes the test fail with an assertion.
  2. NULL names. getTagID returns -1 for a NULL key and skips NULL field names rather than passing them to strcmp.
  3. Type punning. reinterpret_cast over the pool is now a static_cast through void*, with a compile-time check that the pool starts with the empty string at offset 0.
  4. Provenance. No code change. The original attribution and fork copyright in TagLibData.h are intact.
  5. Data spot-check. Built master's TagLib.cpp and this branch's separately and dumped, for every model and every tag ID 0-0xFFFF, the field name (with the unknown-tag fallback), the description, and the reverse getTagID lookup. The two outputs are byte-identical (1,574,165 lines).

Tested on macOS (CMake, Release, BUILD_TESTS=ON): 18/18 tests pass. MSVC and other platforms are left to CI.

andre-rosa and others added 4 commits November 6, 2026 11:06
Store metadata descriptors in sorted constant arrays instead of constructing
per-model maps at initialization. Binary search handles tag IDs; reverse name
lookup preserves the existing lowest-ID result for duplicate names. Descriptors
and their strings keep static storage duration.

Keep every current upstream table, including the empty Apple iOS model, and
preserve tag IDs, strings, public model mappings, and unknown-tag fallbacks.
Metadata initialization now performs zero allocations. In a native x86-64
measurement, the current tables previously retained 64,752 requested bytes in
1,349 allocations per initialized library instance.

Add a standalone metadata regression test covering all 16-bit tag IDs for every
registered model, sorted table invariants, reverse names, stable pointers,
unknown models, and fallback strings.
Replace metadata string pointers with compiler-computed 16-bit offsets.
Keep each model in its own constant pool so unused models can be discarded.
A compile-time bound prevents offset overflow; no generator, heap allocation
or runtime initialization is needed. Preserve the existing getters.

Move the table rows and their original attribution to TagLibData.h. Update
header dependencies and add exhaustive string, offset and lookup coverage.
Add an internal getTagFields method and use it at the ten callers that
request both strings. This avoids repeating model dispatch and binary
search. Keep the original three-argument getTagFieldName symbol as a
wrapper, and leave getTagDescription available.

Check both outputs for every model and 16-bit tag ID, including missing
descriptions, unknown tags and fallback buffers. Verify that the original
member-function signature and returned names are preserved.
Follow-up to the constant metadata tables:
- Verify in debug builds that every table has strictly increasing tag IDs the first time TagLib::instance() is used, not only in TagLibTest.
- Make getTagID return -1 for a NULL key and skip any NULL field name instead of passing it to strcmp.
- Replace the reinterpret_cast over a string pool with a static_cast through void*, and add a compile-time check that the pool's leading empty string sits at offset zero.
- Extend TagLibTest to cover the sort check and NULL keys for every model.
@danoli3
danoli3 marked this pull request as ready for review November 9, 2026 08:50
@danoli3
danoli3 merged commit 4e9689d into master Nov 9, 2026
95 checks passed
@danoli3 danoli3 mentioned this pull request Nov 9, 2026
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