Skip to content

Commit

Permalink
Fix #3950: Div by 0 during DXT4 DDS load
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Yurkovich <[email protected]>
  • Loading branch information
jessey-git committed Aug 24, 2023
1 parent 56c734a commit 64c1495
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/dds.imageio/ddsinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,14 @@ DDSInput::internal_readimg(unsigned char* dst, int w, int h, int d)
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
k = (y * w + x) * 4;
dst[k + 0] = (unsigned char)((int)dst[k + 0] * 255
/ (int)dst[k + 3]);
dst[k + 1] = (unsigned char)((int)dst[k + 1] * 255
/ (int)dst[k + 3]);
dst[k + 2] = (unsigned char)((int)dst[k + 2] * 255
/ (int)dst[k + 3]);
if (dst[k + 3]) {
dst[k + 0] = (unsigned char)((int)dst[k + 0] * 255
/ (int)dst[k + 3]);
dst[k + 1] = (unsigned char)((int)dst[k + 1] * 255
/ (int)dst[k + 3]);
dst[k + 2] = (unsigned char)((int)dst[k + 2] * 255
/ (int)dst[k + 3]);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions testsuite/dds/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,9 @@ src/crash-1634.dds : 16 x 8, 1 channel, uint8 dds
oiiotool ERROR: read : "src/crash-1635.dds": Unsupported DDS bit depth: 1048576 (maybe it's a corrupted file?)
Full command line was:
> oiiotool --info -v -a --hash src/crash-1635.dds
Reading src/crash-3950.dds
src/crash-3950.dds : 16 x 1, 3 channel, uint8 dds
SHA-1: 430EFD5F1F3B2D6D48D10C3836D8FD4C83CA47C7
channel list: R, G, B
compression: "DXT4"
textureformat: "Plain Texture"
1 change: 1 addition & 0 deletions testsuite/dds/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@
# Test more corrupted files or those that used to crash
command += info_command ("src/crash-1634.dds", hash=True)
command += info_command ("src/crash-1635.dds", hash=True)
command += info_command ("src/crash-3950.dds", hash=True)
Binary file added testsuite/dds/src/crash-3950.dds
Binary file not shown.

0 comments on commit 64c1495

Please sign in to comment.