Skip to content
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