Mercurial > hg > octave-nkf
changeset 17912:01496d4811b1
imread: deal elegantly with multiples frames of different sizes.
* __magick_read__.cc (F__magick_read__): when attempting to read multiple
frames of an image file, check that they all have the same dimensions to
avoid segfaulting later while trying to access pixels that do not exist.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Wed, 13 Nov 2013 02:49:06 +0000 |
parents | c98ffba88c78 |
children | 730bc06134f9 |
files | libinterp/dldfcn/__magick_read__.cc |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/dldfcn/__magick_read__.cc +++ b/libinterp/dldfcn/__magick_read__.cc @@ -757,12 +757,33 @@ frameidx(i)--; if (frameidx(i) < 0 || frameidx(i) > nFrames - 1) { + // We do this check inside the loop because frameidx does not + // need to be ordered (this is a feature and even allows for + // some frames to be read multiple times). error ("imread: index/frames specified are outside the number of images"); return output; } } } + // Check that all frames have the same size. We don't do this at the same + // time we decode the image because that's done in many different places, + // to cover the different types of images which would lead to a lot of + // copy and paste. + const unsigned int nRows = imvec[frameidx(0)].rows (); + const unsigned int nCols = imvec[frameidx(0)].columns (); + for (octave_idx_type frame = 0; frame < nFrames; frame++) + { + if (nRows != imvec[frameidx(frame)].rows () || + nCols != imvec[frameidx(frame)].columns ()) + { + error ("imread: all frames must have the same size but frame %i is different", + frameidx(frame) +1); + error_state = 1; + } + } + + const octave_idx_type depth = get_depth (imvec[frameidx(0)]); if (is_indexed (imvec[frameidx(0)])) {