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

Fix vague error message when trying to import a WAV file that is too large #91077

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bs-mwoerner
Copy link
Contributor

Fixes #90957.

This is certainly an edge case (we're talking about more than 3 hours of audio in a single stream), but I suppose the error message could be a bit nicer than "Condition "p_size < 0"".

I also fixed an edge case in AudioStreamWAV, where the size calculation would overflow when adding the padding bytes to a size that's already close to INT_MAX.

I looked into truly supporting 4 GiB WAVs, but that doesn't seem feasible, because it runs into problems with saving the binary resource later, so that would require some more fundamental changes.

@@ -197,6 +197,8 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
break;
}

ERR_FAIL_COND_V_MSG(chunksize > INT_MAX, ERR_INVALID_DATA, "WAV file '" + p_source_file + "' is too large (> 2 GiB of data). Try using a compressed format such as Ogg Vorbis or MP3 instead.");
Copy link
Contributor

@jsjtxietian jsjtxietian Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or try split the resource and shorten the audio length?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could truncate the stream, but I'm not sure this would benefit anyone. I can think of scenarios where such a huge file might end up in the project tree, but I can't think of any where you'd actually want Godot to import it. Doing a partial import of such a file might just produce gigabytes of unused data in the exported game.

Copy link
Contributor

@jsjtxietian jsjtxietian Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I mean we can suggest the user to truncate the stream manually instead of import it as a whole (if they really want the wav format).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I misread your comment. How about "WAV file 'xxx' is too large (> 2 GiB of data). Try shortening or splitting it or use a compressed format such as Ogg Vorbis or MP3 instead."?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bs-mwoerner: you got an "OK". I guess we can continue with getting this merged?

Maybe we can add something to the docs of AudioStream (or AudioStreamWAV), that audio file must be <= 4 GiB ?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MJacred You're right, I missed the "thumbs up". I've updated the commit with the new wording.

The limit is actually 2 GiB of actual data, because the limiting factor here isn't the WAV format itself but the way Godot stores binary resources, so the stream after importing can't be longer than INT_MAX bytes. We can add that to the docs (I've never comitted to the documentation before but there's a first time for everything.) Would it make sense to include the doc update in this pull request?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Godot can do more the int max

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I originally checked this, but I may have stopped looking prematurely when I saw that ResourceFormatSaverBinaryInstance::write_variant() treated sizes > 2 GiB as negative lengths. At second glance, it seems to mostly call methods that reinterpret this as an unsigned int, so the overflows should cancel out. In that case, the problem may indeed just be the WAV stream itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to include the doc update in this pull request?

Yes :)

…s with more than 2 GiB of data.

Fixed a possible overflow in AudioStreamWAV::set_data() when trying to set data with a size close to INT_MAX.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsafe cast when loading WAV files
6 participants