Skip to content

Unsafe cast when loading WAV files #90957

@ndbn

Description

@ndbn

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions