summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-08-21 00:10:06 +0200
committerGitHub <noreply@github.com>2018-08-21 00:10:06 +0200
commitad8a6b10b51bc6ec133ba370e71c0408f645e6da (patch)
tree75780011dca8cfd8037fd5dad19b1165bfae8d76
parent35d232b10018899261253aa13249fae58d08be9d (diff)
parentec68822cd7cea75de4bbf44fce9bf83ae5e89612 (diff)
Merge pull request #21220 from Noshyaar/import-crash
Fix crash while importing corrupt wav
-rw-r--r--editor/import/resource_importer_wav.cpp24
-rw-r--r--servers/audio/effects/audio_effect_record.cpp2
2 files changed, 15 insertions, 11 deletions
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index 41f5a892eb..9e99dcc5c8 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -157,15 +157,18 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
//Consider revision for engine version 3.0
compression_code = file->get_16();
if (compression_code != 1 && compression_code != 3) {
- ERR_PRINT("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead.");
- break;
+ file->close();
+ memdelete(file);
+ ERR_EXPLAIN("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead.");
+ ERR_FAIL_V(ERR_INVALID_DATA);
}
format_channels = file->get_16();
if (format_channels != 1 && format_channels != 2) {
-
- ERR_PRINT("Format not supported for WAVE file (not stereo or mono)");
- break;
+ file->close();
+ memdelete(file);
+ ERR_EXPLAIN("Format not supported for WAVE file (not stereo or mono).");
+ ERR_FAIL_V(ERR_INVALID_DATA);
}
format_freq = file->get_32(); //sampling rate
@@ -174,10 +177,11 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
file->get_16(); // block align (unused)
format_bits = file->get_16(); // bits per sample
- if (format_bits % 8) {
-
- ERR_PRINT("Strange number of bits in sample (not 8,16,24,32)");
- break;
+ if (format_bits % 8 || format_bits == 0) {
+ file->close();
+ memdelete(file);
+ ERR_EXPLAIN("Invalid amount of bits in the sample (should be one of 8, 16, 24 or 32).");
+ ERR_FAIL_V(ERR_INVALID_DATA);
}
/* Don't need anything else, continue */
@@ -185,7 +189,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
}
if (chunkID[0] == 'd' && chunkID[1] == 'a' && chunkID[2] == 't' && chunkID[3] == 'a' && !data_found) {
- /* IS FORMAT CHUNK */
+ /* IS DATA CHUNK */
data_found = true;
if (!format_found) {
diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp
index 74a6838d1a..78ba658ed8 100644
--- a/servers/audio/effects/audio_effect_record.cpp
+++ b/servers/audio/effects/audio_effect_record.cpp
@@ -233,7 +233,7 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const {
w[i * 2 + 1] = rr[i];
}
} else {
- ERR_EXPLAIN("format not implemented");
+ ERR_PRINT("Format not implemented.");
}
Ref<AudioStreamSample> sample;