[core] avoid overflow when channel muxing

This commit is contained in:
Dragos Oancea
2020-01-17 20:58:57 +00:00
committed by Andrey Volk
parent a28436deb7
commit c2e80ea1e3
2 changed files with 63 additions and 3 deletions
+5 -3
View File
@@ -589,15 +589,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
if (fh->real_channels != fh->channels && !switch_test_flag(fh, SWITCH_FILE_NOMUX)) {
int need = *len * 2 * fh->real_channels;
int need = *len * 2 * (fh->real_channels > fh->channels ? fh->real_channels : fh->channels);
if (need > fh->muxlen) {
fh->muxbuf = realloc(fh->muxbuf, need);
switch_assert(fh->muxbuf);
fh->muxlen = need;
memcpy(fh->muxbuf, data, fh->muxlen);
data = fh->muxbuf;
}
if (fh->muxbuf) {
memcpy(fh->muxbuf, data, *len * 2);
data = fh->muxbuf;
}
switch_mux_channels((int16_t *) data, *len, fh->real_channels, fh->channels);