ref: 40307422b42c64319ef059131c6162e67e777465
parent: 8f56cc624c902970b48d255eec8ef1ee15715a63
author: Mark Harris <mark.hsj@gmail.com>
date: Sun Sep 8 15:35:09 EDT 2019
opusdec: Write WAV size up to 4 GiB The WAV size fields are unsigned 32-bit integers. Fill them in if the size would be less than 0xffffffff; otherwise use 0xffffffff to indicate that the chunk continues until end of file (an unofficial convention to allow WAV files larger than 4 GiB, when no chunks follow the audio data).
--- a/src/wav_io.c
+++ b/src/wav_io.c
@@ -83,7 +83,7 @@
extensible |= fp;
ret = fprintf(file, "RIFF") >= 0;
- ret &= fwrite_le32(0x7fffffff, file);
+ ret &= fwrite_le32(0xffffffff, file);
ret &= fprintf(file, "WAVEfmt ") >= 0;
ret &= fwrite_le32(extensible ? 40 : 16, file);
@@ -135,7 +135,7 @@
}
ret &= fprintf(file, "data") >= 0;
- ret &= fwrite_le32(0x7fffffff, file);
+ ret &= fwrite_le32(0xffffffff, file);
return !ret ? -1 : extensible ? 40 : 16;
}
@@ -147,12 +147,18 @@
{
opus_int32 write_val;
- if (format <= 0 || audio_size >= 0x7fffffff) return 0;
- if (fseek(file, 4, SEEK_SET) != 0) return -1;
- write_val = le_int((opus_int32)(audio_size + 20 + format));
- if (fwrite(&write_val, 4, 1, file) != 1) return -1;
- if (fseek(file, 16 + format, SEEK_CUR) != 0) return -1;
- write_val = le_int((opus_int32)audio_size);
- if (fwrite(&write_val, 4, 1, file) != 1) return -1;
+ if (format <= 0 || audio_size < 0) return 0;
+ if (audio_size < (opus_int64)0xffffffffU - 20 - format)
+ {
+ if (fseek(file, 4, SEEK_SET) != 0) return -1;
+ write_val = le_int((opus_int32)(audio_size + 20 + format));
+ if (fwrite(&write_val, 4, 1, file) != 1) return -1;
+ }
+ if (audio_size < (opus_int64)0xffffffffU)
+ {
+ if (fseek(file, 24 + format, SEEK_SET) != 0) return -1;
+ write_val = le_int((opus_int32)audio_size);
+ if (fwrite(&write_val, 4, 1, file) != 1) return -1;
+ }
return 0;
}