Skip to content

Commit

Permalink
FIX: crash when decoding image from invalid data on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jul 5, 2022
1 parent 0b50d9c commit 446a1e7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/os/osx/host-image.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
**
***********************************************************************/
{
DecodeImageFromFile(uri, frame, codi);
codi->error = DecodeImageFromFile(uri, frame, codi);
}

/***********************************************************************
Expand All @@ -52,7 +52,7 @@
**
***********************************************************************/
{
EncodeImageToFile(uri, codi);
codi->error = EncodeImageToFile(uri, codi);
}

/***********************************************************************
Expand Down
44 changes: 44 additions & 0 deletions src/tests/units/codecs-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,15 @@ if find codecs 'PNG [
img/rgb = #{C800000000C800C800FFFFFF}
]
try [delete %new.png]

--test-- "encode/decode PNG"
--assert all [
binary? try [b: encode 'png make image! 1x1]
image? try [i: decode 'png b]
i/rgb == #{FFFFFF}
]
;@@ https://github.com/Oldes/Rebol-issues/issues/2503
--assert error? try [decode 'png #{}]
===end-group===
]

Expand All @@ -476,6 +485,14 @@ if find codecs 'QOI [
--test-- "qoi/size?"
--assert 256x256 = codecs/qoi/size? %test.qoi
try [delete %test.qoi]
--test-- "encode/decode QOI"
--assert all [
binary? try [b: encode 'qoi make image! 1x1]
image? try [i: decode 'qoi b]
i/rgb == #{FFFFFF}
]
;@@ https://github.com/Oldes/Rebol-issues/issues/2503
--assert error? try [decode 'qoi #{}]
===end-group===
]

Expand All @@ -491,6 +508,15 @@ if find codecs 'JPEG [
--assert 256x256 = codecs/jpeg/size? %units/files/flower-from-photoshop.jpg
--assert 256x256 = codecs/jpeg/size? %units/files/flower-tiny.jpg
--assert none? codecs/jpeg/size? %units/files/test.aar

--test-- "encode/decode JPEG"
--assert all [
binary? try [b: encode 'jpeg make image! 1x1]
image? try [i: decode 'jpeg b]
i/rgb == #{FFFFFF}
]
;@@ https://github.com/Oldes/Rebol-issues/issues/2503
--assert error? try [decode 'jpeg #{}]
===end-group===
]

Expand All @@ -500,6 +526,15 @@ if find codecs 'GIF [
--assert 256x256 = codecs/gif/size? %units/files/flower.gif
--assert none? codecs/gif/size? %units/files/test.aar

--test-- "encode/decode GIF"
--assert all [
binary? try [b: encode 'gif make image! 1x1]
image? try [i: decode 'gif b]
i/rgb == #{FFFFFF}
]
;@@ https://github.com/Oldes/Rebol-issues/issues/2503
--assert error? try [decode 'gif #{}]

--test-- "gif rgb image"
;@@ https://github.com/Oldes/Rebol-issues/issues/2495
--assert all [
Expand All @@ -522,6 +557,15 @@ if find codecs 'BMP [
--test-- "bmp/size?"
--assert 256x256 = codecs/bmp/size? %units/files/flower.bmp
--assert none? codecs/bmp/size? %units/files/test.aar
--test-- "encode/decode BMP"
--assert all [
binary? try [b: encode 'bmp make image! 1x1]
image? try [i: decode 'bmp b]
i/rgb == #{FFFFFF}
]
;@@ https://github.com/Oldes/Rebol-issues/issues/2503
--assert error? try [decode 'bmp #{}]

===end-group===
]

Expand Down

0 comments on commit 446a1e7

Please sign in to comment.