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

flac: Fix improper buffer reusing #732

Merged
merged 3 commits into from Apr 20, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Next
flac: Fix improper buffer reusing
  • Loading branch information
yuawn committed Apr 14, 2021
commit 4c30646abf7834e406f7e2429c70bc254e18beab
8 changes: 8 additions & 0 deletions src/flac.c
Expand Up @@ -62,6 +62,7 @@ typedef struct
FLAC__StreamMetadata *metadata ;

const int32_t * const * wbuffer ;
unsigned wbuffer_size ;
int32_t * rbuffer [FLAC__MAX_CHANNELS] ;

int32_t* encbuffer ;
Expand Down Expand Up @@ -188,6 +189,12 @@ flac_buffer_copy (SF_PRIVATE *psf)
return 0 ;
} ;

if (frame->header.blocksize > pflac->wbuffer_size)
{ psf_log_printf (psf, "Ooops : frame->header.blocksize (%d) > pflac->wbuffer_size (%d)\n", __func__, __LINE__, frame->header.blocksize, pflac->wbuffer_size) ;
psf->error = SFE_INTERNAL ;
return 0 ;
} ;

if (frame->header.channels > FLAC__MAX_CHANNELS)
psf_log_printf (psf, "Ooops : frame->header.channels (%d) > FLAC__MAX_BLOCK_SIZE (%d)\n", __func__, __LINE__, frame->header.channels, FLAC__MAX_CHANNELS) ;

Expand Down Expand Up @@ -393,6 +400,7 @@ sf_flac_write_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC
pflac->bufferpos = 0 ;

pflac->wbuffer = buffer ;
pflac->wbuffer_size = pflac->frame->header.blocksize ;

flac_buffer_copy (psf) ;

Expand Down