Ignore:
Timestamp:
Dec 16, 2018, 7:10:35 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
6f601bd
Parents:
4f75d8a
Message:

[io] validate input in sink_wavwrite_do

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_wavwrite.c

    r4f75d8a re4c6c76  
    235235void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    236236  uint_t c = 0, i = 0, written_frames = 0;
    237 
    238   if (write > s->max_size) {
    239     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    240         "but only %d can be written at a time\n", write, s->path, s->max_size);
    241     write = s->max_size;
    242   }
     237  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
     238      s->max_size, write_data->length, write);
    243239
    244240  for (c = 0; c < s->channels; c++) {
    245     for (i = 0; i < write; i++) {
     241    for (i = 0; i < length; i++) {
    246242      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
    247243    }
    248244  }
    249   written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
     245  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    250246
    251247  if (written_frames != write) {
     
    260256  uint_t c = 0, i = 0, written_frames = 0;
    261257
    262   if (write > s->max_size) {
    263     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    264         "but only %d can be written at a time\n", write, s->path, s->max_size);
    265     write = s->max_size;
    266   }
    267 
    268   for (c = 0; c < s->channels; c++) {
    269     for (i = 0; i < write; i++) {
     258  uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path,
     259      s->channels, write_data->height);
     260  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
     261      s->max_size, write_data->length, write);
     262
     263  for (c = 0; c < channels; c++) {
     264    for (i = 0; i < length; i++) {
    270265      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[c][i]));
    271266    }
    272267  }
    273   written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
     268  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    274269
    275270  if (written_frames != write * s->channels) {
Note: See TracChangeset for help on using the changeset viewer.