gh-117716: Fix wave RIFF padding for data chunks#145237
Conversation
a59aae9 to
f8ff230
Compare
|
Looking at the document referenced in the issue (emphasis mine):
In this PR, the size includes the padding byte. Which is right? |
|
@mbeijen, do you have an answer? |
wave.Wave_write now writes the required RIFF pad byte when the data chunk size is odd. Update RIFF chunk size calculations in both header writing and header patching so they include the alignment pad byte when present. Add a regression test in test_wave.py that verifies odd-sized writes are padded, RIFF size is correct, and roundtrip reads preserve frame data.
f8ff230 to
ff3f783
Compare
Sure, and thanks for following up!! Plus, I've rebased the commit so it now applies cleanly after my other PRs affecting The spec quote "ckSize does not include the pad byte" applies to each sub-chunk's own ckSize. The RIFF form's ckSize represents total file content minus the 8-byte RIFF header, which physically includes the pad byte. I double-checked this with libsndfile (what audacity uses) and it does exactly the same thing as this fix. I verified this against libsndfile 1.2.2: for 1 byte of audio it writes data ckSize = 1 and RIFF ckSize = 38 (= 36 + 1 + 1), matching this PR exactly. |
|
I see, that makes sense. Thanks for double-checking! |
wave.Wave_write now writes the required RIFF pad byte when the data chunk size is odd.
Update RIFF chunk size calculations in both header writing and header patching so they include the alignment pad byte when present.
Add a regression test in test_wave.py that verifies odd-sized writes are padded, RIFF size is correct, and roundtrip reads preserve frame data.
Wave_writedoes not writepad byte#117716