I'm attempting to read a zip file in PHP that I know has a CRC error. Unfortunately, it looks like I can only get 31 bytes of the file to read. Using just $zip->getFromName()
gives no errors but just reads 31 bytes
$zip = new ZipArchive;
$zip->open("path/to/corrupted.zip");
// $contents will become just 31 bytes
$contents = $zip->getFromName("file/in/zip.txt");
Trying to read from the stream $zip->getStream()
will give a CRC error, and again will only read 31 bytes
$fp = $zip->getStream("file/in/zip.txt");
$contents = "";
while (!feof($fp)) {
// Gives the error "fread(): Zip stream error: CRC error in ..."
// Using 1 instead of 2 still only reads 31 bytes but gives no error
$contents .= fread($fp, 2);
}
fclose($fp);
So, is there any way I could ignore this CRC error, and read the file anyways?
A little background: my website pre-processes .jar files users upload before they're downloaded by others. Users will occasionally upload a valid .jar file with CRC errors in an attempt to deter people from decompiling it. However, I still want to be able to pre-process these files for download.
I have a different pre-processor written in Python, and I was able to pretty easily disable the CRC check by modifying the zipfile library and commenting out the line that does the crc check. Is there any easy way I could do a similar thing in PHP without needing to make my own ZipFile library? I suppose worst case that's what I'll need to do.