Merge branch 'GP-7131_ryanmkurtz_PR-9453_kaibolay_reasonable-image-size'

This commit is contained in:
Ryan Kurtz
2026-08-10 12:59:08 -04:00
4 changed files with 25 additions and 37 deletions

View File

@@ -18,7 +18,7 @@ public class CrushedPNGUtil {
* the structure and formatting of a normal non-crushed PNG. * the structure and formatting of a normal non-crushed PNG.
* @param png the CrushedPNG object * @param png the CrushedPNG object
* @return An InputStream of the correctly formated bytes of a png * @return An InputStream of the correctly formated bytes of a png
* @throws Exception * @throws Exception an a problem occurred
*/ */
public static byte[] getUncrushedPNGBytes(ProcessedPNG png) throws Exception { public static byte[] getUncrushedPNGBytes(ProcessedPNG png) throws Exception {
boolean foundIHDR = false; boolean foundIHDR = false;
@@ -190,7 +190,7 @@ public class CrushedPNGUtil {
* Does the processing to uncrushify the PNG IDAT chunks * Does the processing to uncrushify the PNG IDAT chunks
* @param ihdrChunk the IHDR chunk to pull meta deta from * @param ihdrChunk the IHDR chunk to pull meta deta from
* @param decompressedResult result of the zlib decompression * @param decompressedResult result of the zlib decompression
* @throws PNGFormatException * @throws PNGFormatException if problem occurred
*/ */
private static void processIDATChunks(IHDRChunk ihdrChunk, byte[] decompressedResult) private static void processIDATChunks(IHDRChunk ihdrChunk, byte[] decompressedResult)
throws PNGFormatException { throws PNGFormatException {
@@ -549,25 +549,6 @@ public class CrushedPNGUtil {
} }
/**
* Prepends the needed Zlib header to the set of idatChunks
* in order to inflate the bytes
* @param idatChunks the set of idat chunks
* @return idat chunks with the new header
*/
private static byte[] getFixedIdatDataBytes(ByteArrayOutputStream idatChunks) {
//Prepend the needed Zlib header info to the IDAT chunk data
byte[] idatData = idatChunks.toByteArray();
byte[] fixedIdatData = new byte[idatData.length + 2];
fixedIdatData[0] = ZLIB.ZLIB_COMPRESSION_DEFAULT[0];
fixedIdatData[1] = ZLIB.ZLIB_COMPRESSION_DEFAULT[1];
for (int i = 0; i < idatData.length; i++) {
fixedIdatData[i + 2] = idatData[i];
}
return fixedIdatData;
}
/** /**
* Calculates the crc32 based on a byte[] * Calculates the crc32 based on a byte[]
* @param data the byte array to calculate crc32 from * @param data the byte array to calculate crc32 from

View File

@@ -37,7 +37,7 @@ public class IHDRChunk {
* Represents the IHDR chunk to process and return the important * Represents the IHDR chunk to process and return the important
* metadata within this chunk. * metadata within this chunk.
* @param chunk the chunk to process as an IHDR chunk * @param chunk the chunk to process as an IHDR chunk
* @throws IOException * @throws IOException if an IO-related error occurred
*/ */
public IHDRChunk(PNGChunk chunk) throws IOException { public IHDRChunk(PNGChunk chunk) throws IOException {
if (chunk.getIDString().equals(CrushedPNGConstants.IHDR_STRING)) { if (chunk.getIDString().equals(CrushedPNGConstants.IHDR_STRING)) {
@@ -49,7 +49,13 @@ public class IHDRChunk {
ByteBuffer buff = ByteBuffer.wrap(data); ByteBuffer buff = ByteBuffer.wrap(data);
imgWidth = buff.getInt(); imgWidth = buff.getInt();
if (imgWidth <= 0 || imgWidth > 65535) {
throw new IllegalArgumentException("Invalid image width: " + imgWidth);
}
imgHeight = buff.getInt(); imgHeight = buff.getInt();
if (imgHeight <= 0 || imgHeight > 65535) {
throw new IllegalArgumentException("Invalid image height: " + imgHeight);
}
bitDepth = buff.get(); bitDepth = buff.get();
colorType = buff.get(); colorType = buff.get();
compressionMethod = buff.get(); compressionMethod = buff.get();

View File

@@ -15,15 +15,15 @@
*/ */
package ghidra.file.formats.ios.png; package ghidra.file.formats.ios.png;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter; import ghidra.app.util.bin.StructConverter;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.DuplicateNameException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class PNGChunk implements StructConverter { public class PNGChunk implements StructConverter {
private int length; private int length;
@@ -35,8 +35,8 @@ public class PNGChunk implements StructConverter {
/** /**
* Reads in the bytes of a PNG chunk from a given * Reads in the bytes of a PNG chunk from a given
* BinaryReader * BinaryReader
* @param reader * @param reader A {@link BinaryReader} positioned at the start of the PNG chunk
* @throws IOException * @throws IOException if an IO-related error occurred
*/ */
public PNGChunk(BinaryReader reader) throws IOException { public PNGChunk(BinaryReader reader) throws IOException {
length = reader.readNextInt(); length = reader.readNextInt();

View File

@@ -15,16 +15,16 @@
*/ */
package ghidra.file.formats.ios.png; package ghidra.file.formats.ios.png;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter; import ghidra.app.util.bin.StructConverter;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.DuplicateNameException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ProcessedPNG implements StructConverter { public class ProcessedPNG implements StructConverter {
private byte[] fileSignature; private byte[] fileSignature;
@@ -35,7 +35,8 @@ public class ProcessedPNG implements StructConverter {
/** /**
* Processes PNG data finding each of the PNG chunks * Processes PNG data finding each of the PNG chunks
* @param reader BinaryReader for the PNG data * @param reader BinaryReader for the PNG data
* @throws IOException * @param monitor A {@link TaskMonitor}
* @throws IOException if an IO-related error occurred
*/ */
public ProcessedPNG(BinaryReader reader, TaskMonitor monitor) throws IOException { public ProcessedPNG(BinaryReader reader, TaskMonitor monitor) throws IOException {
if (reader != null) { if (reader != null) {