Skip to content

Ghidra is a software reverse engineering (SRE) framework

Fix handling of ADAM7 interlacing: - fix calculation of row filter bytes - fix unpacking check

Kai Bolayc574f939f18e
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java
index 752853ad96..264a9db7cc 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java
@@ -207,8 +207,9 @@ public class CrushedPNGUtil {
throws PNGFormatException {
int width;
int height;
- if (ihdrChunk.getInterlaceMethod() == 1) {
+ if (ihdrChunk.getInterlaceMethod() == CrushedPNGConstants.ADAM7_INTERLACE) {
//Msg.debug(this, "Checking Adam7 unpacking");
+ int y = 0;
for (int pass = 0; pass < CrushedPNGConstants.STARTING_COL.length; pass++) {
width =
(ihdrChunk.getImgWidth() - CrushedPNGConstants.STARTING_COL[pass] +
@@ -220,7 +221,6 @@ public class CrushedPNGUtil {
CrushedPNGConstants.ROW_INCREMENT[pass];
int row = 0;
- int y = 0;
while (row < height) {
if (decompressedResult[y] > 4) {
throw new PNGFormatException("Unknown row filter type " +
@@ -236,7 +236,7 @@ public class CrushedPNGUtil {
}
}
- int y = 0;
+ y = 0;
for (int pass = 0; pass < CrushedPNGConstants.STARTING_COL.length; pass++) {
//Formula taken from pngcheck
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/IHDRChunk.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/IHDRChunk.java
index 0e53f44fab..013244dd9e 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/IHDRChunk.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/IHDRChunk.java
@@ -133,13 +133,14 @@ public class IHDRChunk {
for (int pass = 0; pass < CrushedPNGConstants.STARTING_ROW.length; pass++) {
int height =
- (imgHeight - CrushedPNGConstants.STARTING_ROW[pass] + CrushedPNGConstants.ROW_INCREMENT[pass - 1]) /
+ (imgHeight - CrushedPNGConstants.STARTING_ROW[pass] + CrushedPNGConstants.ROW_INCREMENT[pass] - 1) /
CrushedPNGConstants.ROW_INCREMENT[pass];
rowFilterBytes += height;
}
+ } else {
+ rowFilterBytes = imgHeight;
}
- rowFilterBytes = imgHeight;
}
public int getImgWidth() {