commit 6c3229d7041a49bb68f54c7d151a5fd196844b0e
parent 439e61a508660c5e2b595d9458bfd9489faf06fb
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Tue, 29 Oct 2024 12:12:36 +0800
icns.Decode{All}: explicitly error on unsupported formats
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/reader.go b/reader.go
@@ -23,6 +23,9 @@ func Decode(r io.Reader) (image.Image, error) {
return icons[ii].OsType.Size > icons[jj].OsType.Size
})
icon := icons[0]
+ if icon.IconDescription.ImageFormat == ImageFormatJPEG2000 {
+ return nil, fmt.Errorf("decoding largest image (icon %s %s): unsupported format", icon.OsType, icon.ImageFormat)
+ }
img, _, err := image.Decode(icon.r)
if err != nil {
return nil, fmt.Errorf("decoding largest image (icon %s %s): %w", icon.OsType, icon.ImageFormat, err)
@@ -48,6 +51,9 @@ func DecodeAll(r io.Reader) (images []image.Image, err error) {
}
images = append(images, img)
}
+ if len(images) == 0 {
+ return nil, fmt.Errorf("no supported icons found")
+ }
sort.Slice(images, func(ii, jj int) bool {
var (
left = images[ii].Bounds().Size()