Changeset ec3f25f9 for src


Ignore:
Timestamp:
Dec 20, 2018, 6:19:22 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:
9b5aa50
Parents:
f5a97ed
Message:

[source_wavread] validate input sizes to prevent invalid reads

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_wavread.c

    rf5a97ed rec3f25f9  
    2525#include "fvec.h"
    2626#include "fmat.h"
     27#include "ioutils.h"
    2728#include "source_wavread.h"
    2829
     
    348349  uint_t end = 0;
    349350  uint_t total_wrote = 0;
     351  uint_t length = aubio_source_validate_input_length("source_wavread", s->path,
     352      s->hop_size, read_data->length);
    350353  if (s->fid == NULL) {
    351354    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    353356    return;
    354357  }
    355   while (total_wrote < s->hop_size) {
    356     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     358  while (total_wrote < length) {
     359    end = MIN(s->read_samples - s->read_index, length - total_wrote);
    357360    for (i = 0; i < end; i++) {
    358361      read_data->data[i + total_wrote] = 0;
     
    363366    }
    364367    total_wrote += end;
    365     if (total_wrote < s->hop_size) {
     368    if (total_wrote < length) {
    366369      uint_t wavread_read = 0;
    367370      aubio_source_wavread_readframe(s, &wavread_read);
     
    375378    }
    376379  }
    377   if (total_wrote < s->hop_size) {
    378     for (i = end; i < s->hop_size; i++) {
     380  if (total_wrote < length) {
     381    for (i = end; i < length; i++) {
    379382      read_data->data[i] = 0.;
    380383    }
     
    387390  uint_t end = 0;
    388391  uint_t total_wrote = 0;
     392  uint_t length = aubio_source_validate_input_length("source_wavread", s->path,
     393      s->hop_size, read_data->length);
     394  uint_t channels = aubio_source_validate_input_channels("source_wavread",
     395      s->path, s->input_channels, read_data->height);
    389396  if (s->fid == NULL) {
    390397    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    392399    return;
    393400  }
    394   while (total_wrote < s->hop_size) {
    395     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    396     for (j = 0; j < read_data->height; j++) {
     401  while (total_wrote < length) {
     402    end = MIN(s->read_samples - s->read_index, length - total_wrote);
     403    for (j = 0; j < channels; j++) {
    397404      for (i = 0; i < end; i++) {
    398405        read_data->data[j][i + total_wrote] = s->output->data[j][i];
     
    400407    }
    401408    total_wrote += end;
    402     if (total_wrote < s->hop_size) {
     409    if (total_wrote < length) {
    403410      uint_t wavread_read = 0;
    404411      aubio_source_wavread_readframe(s, &wavread_read);
     
    412419    }
    413420  }
    414   if (total_wrote < s->hop_size) {
     421  if (total_wrote < length) {
    415422    for (j = 0; j < read_data->height; j++) {
    416       for (i = end; i < s->hop_size; i++) {
     423      for (i = end; i < length; i++) {
    417424        read_data->data[j][i] = 0.;
    418425      }
Note: See TracChangeset for help on using the changeset viewer.