Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
b5401b94
Unverified
Commit
b5401b94
authored
Jun 22, 2023
by
Kobrin Eli
Committed by
GitHub
Jun 22, 2023
Browse files
Fix heap buffer overflow in `decode_png` (#7691)
parent
5178a2e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
0 deletions
+4
-0
test/assets/toosmall_png/heapbof.png
test/assets/toosmall_png/heapbof.png
+0
-0
test/test_image.py
test/test_image.py
+3
-0
torchvision/csrc/io/image/cpu/decode_png.cpp
torchvision/csrc/io/image/cpu/decode_png.cpp
+1
-0
No files found.
test/assets/toosmall_png/heapbof.png
0 → 100644
View file @
b5401b94
7 Bytes
test/test_image.py
View file @
b5401b94
...
...
@@ -32,6 +32,7 @@ DAMAGED_JPEG = os.path.join(IMAGE_ROOT, "damaged_jpeg")
DAMAGED_PNG
=
os
.
path
.
join
(
IMAGE_ROOT
,
"damaged_png"
)
ENCODE_JPEG
=
os
.
path
.
join
(
IMAGE_ROOT
,
"encode_jpeg"
)
INTERLACED_PNG
=
os
.
path
.
join
(
IMAGE_ROOT
,
"interlaced_png"
)
TOOSMALL_PNG
=
os
.
path
.
join
(
IMAGE_ROOT
,
"toosmall_png"
)
IS_WINDOWS
=
sys
.
platform
in
(
"win32"
,
"cygwin"
)
PILLOW_VERSION
=
tuple
(
int
(
x
)
for
x
in
PILLOW_VERSION
.
split
(
"."
))
...
...
@@ -193,6 +194,8 @@ def test_decode_png_errors():
decode_png
(
torch
.
randint
(
3
,
5
,
(
300
,),
dtype
=
torch
.
uint8
))
with
pytest
.
raises
(
RuntimeError
,
match
=
"Out of bound read in decode_png"
):
decode_png
(
read_file
(
os
.
path
.
join
(
DAMAGED_PNG
,
"sigsegv.png"
)))
with
pytest
.
raises
(
RuntimeError
,
match
=
"Content is too small for png"
):
decode_png
(
read_file
(
os
.
path
.
join
(
TOOSMALL_PNG
,
"heapbof.png"
)))
@
pytest
.
mark
.
parametrize
(
...
...
torchvision/csrc/io/image/cpu/decode_png.cpp
View file @
b5401b94
...
...
@@ -49,6 +49,7 @@ torch::Tensor decode_png(
png_destroy_read_struct
(
&
png_ptr
,
&
info_ptr
,
nullptr
);
TORCH_CHECK
(
false
,
"Internal error."
);
}
TORCH_CHECK
(
datap_len
>=
8
,
"Content is too small for png!"
)
auto
is_png
=
!
png_sig_cmp
(
datap
,
0
,
8
);
TORCH_CHECK
(
is_png
,
"Content is not png!"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment