diff --git a/lib/src/formats/psd/psd_channel.dart b/lib/src/formats/psd/psd_channel.dart index 2a295767..9ac30357 100644 --- a/lib/src/formats/psd/psd_channel.dart +++ b/lib/src/formats/psd/psd_channel.dart @@ -106,11 +106,17 @@ class PsdChannel { if (n < 0) { n = 1 - n; final b = src.readByte(); + if ((dstIndex + n) > dst.length) { + n = dst.length - dstIndex; + } for (var i = 0; i < n; ++i) { dst[dstIndex++] = b; } } else { n++; + if ((dstIndex + n) > dst.length) { + n = dst.length - dstIndex; + } for (var i = 0; i < n; ++i) { dst[dstIndex++] = src.readByte(); } diff --git a/lib/src/image/image.dart b/lib/src/image/image.dart index 9d470dac..e46be3a9 100644 --- a/lib/src/image/image.dart +++ b/lib/src/image/image.dart @@ -361,10 +361,6 @@ class Image extends Iterable { Palette? palette, ExifData? exif, IccProfile? iccp}) { - if (numChannels < 1 || numChannels > 4) { - throw ImageException('Invalid number of channels for image $numChannels.' - ' Must be between 1 and 4.'); - } iccProfile = iccp; if (exif != null) { _exif = ExifData.from(exif); diff --git a/test/_data/psd/rle_crash.psd b/test/_data/psd/rle_crash.psd new file mode 100644 index 00000000..b6bfa7e7 Binary files /dev/null and b/test/_data/psd/rle_crash.psd differ