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.
* @param png the CrushedPNG object
* @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 {
boolean foundIHDR = false;
@@ -190,7 +190,7 @@ public class CrushedPNGUtil {
* Does the processing to uncrushify the PNG IDAT chunks
* @param ihdrChunk the IHDR chunk to pull meta deta from
* @param decompressedResult result of the zlib decompression
* @throws PNGFormatException
* @throws PNGFormatException if problem occurred
*/
private static void processIDATChunks(IHDRChunk ihdrChunk, byte[] decompressedResult)
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[]
* @param data the byte array to calculate crc32 from

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,7 +37,7 @@ public class IHDRChunk {
* Represents the IHDR chunk to process and return the important
* metadata within this 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 {
if (chunk.getIDString().equals(CrushedPNGConstants.IHDR_STRING)) {
@@ -49,7 +49,13 @@ public class IHDRChunk {
ByteBuffer buff = ByteBuffer.wrap(data);
imgWidth = buff.getInt();
if (imgWidth <= 0 || imgWidth > 65535) {
throw new IllegalArgumentException("Invalid image width: " + imgWidth);
}
imgHeight = buff.getInt();
if (imgHeight <= 0 || imgHeight > 65535) {
throw new IllegalArgumentException("Invalid image height: " + imgHeight);
}
bitDepth = buff.get();
colorType = buff.get();
compressionMethod = buff.get();

View File

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

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,16 +15,16 @@
*/
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.StructConverter;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.task.TaskMonitor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ProcessedPNG implements StructConverter {
private byte[] fileSignature;
@@ -35,7 +35,8 @@ public class ProcessedPNG implements StructConverter {
/**
* Processes PNG data finding each of the PNG chunks
* @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 {
if (reader != null) {