Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize AIFF / WAVE files to reported data size #515

Closed
wants to merge 1 commit into from

Conversation

phw
Copy link
Collaborator

@phw phw commented Mar 16, 2021

Some AIFF / WAVE files have smaller actual file size then the reported size of their chunks, as trailing null bytes are sometimes truncated.

This patch ensures the chunks fit the file before saving it.

Fixes #496

See also discussion at https://community.metabrainz.org/t/receiving-valueerror-when-saving-some-files/502884/2

Some AIFF / WAVE files have smaller actual file size then the reported size of their chunks, as trailing null bytes are sometimes truncated.

Fixes quodlibet#496
@phw
Copy link
Collaborator Author

phw commented Mar 16, 2021

@phw
Copy link
Collaborator Author

phw commented Mar 16, 2021

Failing tests seem to be unrelated, some TAK test takes longer than expected.

@lazka
Copy link
Member

lazka commented Mar 17, 2021

hmmm, isn't this a security issue? with the source file dictating how much data we write, potentially a lot

@phw
Copy link
Collaborator Author

phw commented Mar 17, 2021

Mmh, maybe. Any other idea how to solve this then?

The majority of cases seems to miss exactly one byte at the end, as a result of the last chunk having an uneven data size and some tools seem to write files with the last padding byte missing. We could limit the check for this case only.

But I have seen at least one case where a larger chunk of the file was missing, probably the implementation omitted all null bytes at the end (at least the existing data seemed to be complete and adding the proper number of null bytes worked).

@phw
Copy link
Collaborator Author

phw commented Mar 17, 2021

Maybe instead:

  • Detect if the last chunk claimed size would exceed the file length and adjust its size field to the max. possible (there isn't more data anyway) without changing file size
  • Handle only missing padding byte at the end of the file (I still think it should actually add it to the file when saving)

@phw phw mentioned this pull request Mar 23, 2021
@phw
Copy link
Collaborator Author

phw commented Mar 23, 2021

@lazka I added #517 for an alternative approach, which avoids trusting the file size and resizing the file.

Closing this PR

@phw phw closed this Mar 23, 2021
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.

Cannot write tags to certain WAV files
2 participants