From 42132c543358cee9f7c3e9e9b15bb6c1063a608e Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 1 Jan 2019 20:11:46 +1100 Subject: [PATCH 1/1] src/wav.c: Fix heap read overflow This is CVE-2018-19758. Closes: https://github.com/erikd/libsndfile/issues/435 Signed-off-by: chenmaodong --- src/wav.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wav.c b/src/wav.c index 9d71aad..5c825f2 100644 --- a/src/wav.c +++ b/src/wav.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 1999-2016 Erik de Castro Lopo +** Copyright (C) 1999-2019 Erik de Castro Lopo ** Copyright (C) 2004-2005 David Viens ** ** This program is free software; you can redistribute it and/or modify @@ -1146,6 +1146,8 @@ wav_write_header (SF_PRIVATE *psf, int calc_length) psf_binheader_writef (psf, "44", 0, 0) ; /* SMTPE format */ psf_binheader_writef (psf, "44", psf->instrument->loop_count, 0) ; + /* Loop count is signed 16 bit number so we limit it range to something sensible. */ + psf->instrument->loop_count &= 0x7fff ; for (tmp = 0 ; tmp < psf->instrument->loop_count ; tmp++) { int type ; @@ -1412,7 +1414,7 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, uint32_t chunklen) } ; psf->instrument->basenote = note ; - psf->instrument->detune = (int8_t)(pitch / (0x40000000 / 25.0) + 0.5) ; + psf->instrument->detune = (int8_t) (pitch / (0x40000000 / 25.0) + 0.5) ; psf->instrument->gain = 1 ; psf->instrument->velocity_lo = psf->instrument->key_lo = 0 ; psf->instrument->velocity_hi = psf->instrument->key_hi = 127 ; -- 1.8.3.1