Skip to content

fix(rva2): use big-endian byte order for volume adjustment#664

Draft
joust wants to merge 1 commit into
eidoriantan:mainfrom
joust:fix/rva2-endianness
Draft

fix(rva2): use big-endian byte order for volume adjustment#664
joust wants to merge 1 commit into
eidoriantan:mainfrom
joust:fix/rva2-endianness

Conversation

@joust
Copy link
Copy Markdown
Contributor

@joust joust commented Apr 15, 2026

Summary

ID3v2.4 §4.11 specifies RVA2 volume adjustment as a 16-bit signed fixed-point value, big-endian per §3. The reader used getInt16(offset, true) (little-endian flag) and the writer used new Int16Array([v]).buffer (host byte order, little-endian on x86/ARM).

The two errors were symmetric, so mp3tag.js-to-mp3tag.js round-trips preserved values — but the bytes on disk are wrong, and every standards-compliant v2.4 reader sees corrupted volumes for every RVA2 frame this library writes.

Changes

  • src/id3v2/parse.mjs: drop the true LE flag on getInt16
  • src/id3v2/write.mjs: manual big-endian byte split [(v >> 8) & 0xff, v & 0xff]
  • test/id3v2/index.cjs: new test asserts raw bytes on disk are big-endian (0x1234 → 0x12 0x34), plus round-trip for positive and negative values

Test plan

  • npm test — 79 passing (78 → 79)
  • New regression test fails on old code, passes on new code
  • Byte-level assertion prevents symmetric-bug recurrence

ID3v2.4 §4.11 specifies RVA2 volume adjustment as a 16-bit signed
fixed-point value. Per §3, all multi-byte integers in ID3 are
big-endian. The reader was using `getInt16(offset, true)` (little-
endian flag) and the writer was using `new Int16Array([v]).buffer`,
which is host byte order (little-endian on every common platform).

The two errors were symmetric, so a mp3tag.js-to-mp3tag.js round-trip
preserved values — but the bytes on disk were wrong, and every
standards-compliant v2.4 reader saw corrupted volumes for every RVA2
frame written by this library.

The new test asserts the raw bytes on disk are big-endian (0x1234
serialises as 0x12 0x34, not 0x34 0x12), so the regression cannot
recur.
@joust joust force-pushed the fix/rva2-endianness branch from 96b919c to 096f53d Compare April 15, 2026 10:17
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.

1 participant