summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2017-02-14 21:21:54 +1100
committerErik de Castro Lopo <erikd@mega-nerd.com>2017-02-14 21:26:43 +1100
commit3a7884bf532b134804a83632527d2de9a6b25a30 (patch)
treee252163b1e658f6f096a5aaa2908c86a2ee4d966
parent841ed1aef939e8f2d424bef8d1690ccc4442a74d (diff)
downloadflac-3a7884bf532b134804a83632527d2de9a6b25a30.tar.gz
flac/encode.c: Fix an integer overflow
When encoding a 24 bit multichannel W64 file on a 32 bit system, a calculation could overflow resulting in a "got partial sample" error and early termination of the encoding process. The fix was to replace the cast to `size_t` (which is only 32 bits on a 32 bit system) with a cast to `uin64_t`. Thanks to Janne Hyvärinen for helping to track down the problem. Closes: https://sourceforge.net/p/flac/bugs/453
-rw-r--r--src/flac/encode.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/flac/encode.c b/src/flac/encode.c
index 73c15765..be3869f0 100644
--- a/src/flac/encode.c
+++ b/src/flac/encode.c
@@ -1387,9 +1387,9 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
case FORMAT_AIFF_C:
while(encoder_session.fmt.iff.data_bytes > 0) {
const size_t bytes_to_read =
- min (sizeof (ubuffer.u8),
- min ((size_t)encoder_session.fmt.iff.data_bytes,
- CHUNK_OF_SAMPLES * (size_t)encoder_session.info.bytes_per_wide_sample));
+ (size_t) min (sizeof (ubuffer.u8),
+ min (encoder_session.fmt.iff.data_bytes,
+ CHUNK_OF_SAMPLES * (uint64_t) encoder_session.info.bytes_per_wide_sample));
size_t bytes_read = fread(ubuffer.u8, sizeof(uint8_t), bytes_to_read, infile);
if(bytes_read == 0) {
if(ferror(infile)) {