Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix heap-buffer-overflow in function ulaw2linear_buf #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions sfcommands/sfconvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
sound files.
*/

#include <limits.h>
#include "config.h"

#ifdef __USE_SGI_HEADERS__
Expand Down Expand Up @@ -321,16 +322,34 @@ void printversion (void)
*/
bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid)
{
const int kBufferFrameCount = 65536;
int frameSize = afGetVirtualFrameSize(infile, trackid, 1);
bool success = true;
void *buffer = NULL;

const int kBufferFrameCount = 65536;
void *buffer = malloc(kBufferFrameCount * frameSize);
if (frameSize <= 0)
{
fprintf(stderr, "afGetVirtualFrameSize error! \n");
return false;
}

if (frameSize > INT_MAX / kBufferFrameCount)
{
fprintf(stderr, "Prevent integer overflow! \n");
return false;
}

buffer = malloc(kBufferFrameCount * frameSize);

if (buffer == NULL)
{
fprintf(stderr, "allocation of bytes failed! \n");
return false;
}

AFframecount totalFrames = afGetFrameCount(infile, AF_DEFAULT_TRACK);
AFframecount totalFramesWritten = 0;

bool success = true;

while (totalFramesWritten < totalFrames)
{
AFframecount framesToRead = totalFrames - totalFramesWritten;
Expand Down