mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
[3.x] ResourceImporterWAV: Detect if data chunk size is larger than the actual size
(cherry picked from commit 57159bcb8c
)
This commit is contained in:
parent
6ba38858f6
commit
d240313513
1 changed files with 14 additions and 1 deletions
|
@ -111,7 +111,15 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GET FILESIZE */
|
/* GET FILESIZE */
|
||||||
file->get_32(); // filesize
|
|
||||||
|
// The file size in header is 8 bytes less than the actual size.
|
||||||
|
// See https://docs.fileformat.com/audio/wav/
|
||||||
|
const int FILE_SIZE_HEADER_OFFSET = 8;
|
||||||
|
uint32_t file_size_header = file->get_32() + FILE_SIZE_HEADER_OFFSET;
|
||||||
|
uint64_t file_size = file->get_len();
|
||||||
|
if (file_size != file_size_header) {
|
||||||
|
WARN_PRINT(vformat("File size %d is %s than the expected size %d.", file_size, file_size > file_size_header ? "larger" : "smaller", file_size_header));
|
||||||
|
}
|
||||||
|
|
||||||
/* CHECK WAVE */
|
/* CHECK WAVE */
|
||||||
|
|
||||||
|
@ -208,7 +216,12 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t remaining_bytes = file_size - file_pos;
|
||||||
frames = chunksize;
|
frames = chunksize;
|
||||||
|
if (remaining_bytes < chunksize) {
|
||||||
|
WARN_PRINT("Data chunk size is smaller than expected. Proceeding with actual data size.");
|
||||||
|
frames = remaining_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
if (format_channels == 0) {
|
if (format_channels == 0) {
|
||||||
file->close();
|
file->close();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue