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

Unsafe cast when loading WAV files #90957

Open
Tracked by #76797
ndbn opened this issue Apr 20, 2024 · 3 comments · May be fixed by #91077
Open
Tracked by #76797

Unsafe cast when loading WAV files #90957

ndbn opened this issue Apr 20, 2024 · 3 comments · May be fixed by #91077

Comments

@ndbn
Copy link

ndbn commented Apr 20, 2024

Tested versions

4.2.1
4.3.dev5

System information

Windows 10 x64

Issue description

There is(link) unsafe cast from uint32_t to int

frames = chunksize;

If you try to load WAV file with size more then INT_MAX (2147483647) you'll get frames < 0, and after some lines of code
you will get a not clear message

ERROR: Condition "p_size < 0" is true. Returning: ERR_INVALID_PARAMETER
at: CowData::resize (core/templates/cowdata.h:314)

Or, if workstation have small amout of RAM (8Gb) - Godot also crash

As a partial solution you can add check like this after this line

if (chunksize > INT_MAX) {
		ERR_FAIL_V_MSG(ERR_INVALID_DATA, "File too big.");
}

but it not well IMO. May be better to constraint file size with understandable message for Godot user.
WAV file can be 4Gb as chunksize is unsigned 32bit int wiki , but in Godot data also stored in Vector<float>, and it require big amount of memory and mine 32Gb not enougth(I try to rebuild Godot changing frames type to uint32_t and got exception with stosb assembler instruction )

Steps to reproduce

Try to import big WAV file, more then 2147483647 bytes

Minimal reproduction project (MRP)

N/A

@jsjtxietian
Copy link
Contributor

As a partial solution you can add check like this after this line

Seems pretty resonable to me, the warning message can be more in detail.

@bs-mwoerner
Copy link
Contributor

I created a pull request with a nicer error message for the condition you indicated.

I've also had a look at the code to see if there's a feasible way to support larger WAV files, but I don't think that's possible. It's not just the WAV importer. Neither the WAV stream nor the resource saver support more than 2 GiB of data in a single object, so if the importer were to support larger WAV files, these would just fail a bit further down the line. Wanting to keep a multi-hour long sound effect in memory is a rather uncommon requirement, so I don't think there's much chance for fundamental changes to Godot in order to support that.

@ndbn
Copy link
Author

ndbn commented Apr 24, 2024

I created a pull request with a nicer error message for the condition you indicated.

I've also had a look at the code to see if there's a feasible way to support larger WAV files, but I don't think that's possible. It's not just the WAV importer. Neither the WAV stream nor the resource saver support more than 2 GiB of data in a single object, so if the importer were to support larger WAV files, these would just fail a bit further down the line. Wanting to keep a multi-hour long sound effect in memory is a rather uncommon requirement, so I don't think there's much chance for fundamental changes to Godot in order to support that.

Thank you. I looked in source to understand how AudioStreamPlayer works and why this error happens. I assumed thаt it load data from file by blocks and play it, (like in foobar2000 for ex.), it was wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants