mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Don't crash from incomplete wav files
This commit is contained in:
parent
4c0077fd84
commit
cbbaf148f4
@ -148,6 +148,7 @@ void WavData::Read(RIFFReader &file_) {
|
||||
|
||||
raw_data = (uint8_t *)malloc(numBytes);
|
||||
raw_data_size = numBytes;
|
||||
|
||||
if (num_channels == 1 || num_channels == 2) {
|
||||
file_.ReadData(raw_data, numBytes);
|
||||
} else {
|
||||
@ -410,7 +411,11 @@ Sample *Sample::Load(const std::string &path) {
|
||||
samples[i] = ConvertU8ToI16(wave.raw_data[i]);
|
||||
}
|
||||
}
|
||||
return new Sample(samples, wave.num_channels, wave.numFrames, wave.sample_rate);
|
||||
|
||||
// Protect against bad metadata.
|
||||
int actualFrames = std::min(wave.numFrames, wave.raw_data_size / wave.raw_bytes_per_frame);
|
||||
|
||||
return new Sample(samples, wave.num_channels, actualFrames, wave.sample_rate);
|
||||
}
|
||||
|
||||
static inline int16_t Clamp16(int32_t sample) {
|
||||
|
Loading…
Reference in New Issue
Block a user