0
votes

I have inherited a zlib compressed file and long story short, I need to UN-zlib-compress this puppy back to its original content.

I have been racking my brain trying to figure out what in the world is happening, but I am hitting a wall and I am hoping you good people will help me out to figure out what's going on.

I have done alot of things so far, I won't bore you with every single thing, but this is what I landed on last, and all I get garbled output, don't know what in the heck is wrong, especially that the last step of decode complains about the data saying:

Warning: gzuncompress(): data error in C:\xampp\htdocs\test-box\index.php on line 6

Warning: zlib_decode(): data error in C:\xampp\htdocs\test-box\index.php on line 8

and this is the code - nothing fancy, I am trying to get it to work before going too crazy with it yet and so the simplicity should allow us to better analyze it.

<?php
    $filename = 'c5ytvbg4y.x';             // this is the zlib compressed file
    $file = filesize($filename);           // using this for the length
    $zd = gzopen($filename, "r");          // create valid pointer
    $contents = gzread($zd, $file);        // binary safe read the content
    $decoded = gzuncompress($contents);    // using gzdecode produces the same issue
    gzclose($zd);                          // close the pointer
    zlib_decode($decoded);                 // decode it but I get nothing but garble
?>

Any assistance would be appreciated. Ideally I want to be able to open it uncompress it back to normal and save it to a new file. But at the moment I would be happy just to find out why in the heck I get nothing but garbled text back. Also keep in mind that I know the $file above is not ideal, I will put a while !feof($zd) or something to that effect later, I wanted to keep it simple for now while trying get the larger issue figured out.

Any thoughts, recommendations, suggestions, code assistance, or whatnot would be greatly appreciated, TIA.

Additions

@Mark's Request:

0A 12 0F 04 04 D8 44 DA BF 63 C4 93 93 3B 49 51 17 A2 6F E3 0C 12 4D E4 24 F6 C8 BA D0 60 76 81
2
Why are you trying to use gz*() instead of just using zlib?Ignacio Vazquez-Abrams
Please provide the first 30 bytes in hex.Mark Adler
certainly, added it to the question, thank you. BTW just in case it matters, I have provided 32 :)GµårÐïåñ
@IgnacioVazquez-Abrams, I have tried it both ways, doesn't matter, says the same error. The only reason I switched to gz was because of a few things I read about it, among other places here on SO but as I said, I have tried many things, including straight away with zlib_* functions. If you can help me with a functional code that uses zlib_* only, by all means please and thank you.GµårÐïåñ

2 Answers

1
votes

It is definitely not a "zlib compressed file", at least not the first 32 bytes, nor is it any format that uses the deflate compression method (e.g. gzip, zip, png, etc.), because there is no valid deflate compressed data in the provided bytes.

0
votes

The zlib header typically starts with hexadecimal 78. Your data starts with 0A, which isn't valid as part of a zlib header. (Technically it is sort of valid, but it implies a compression format that isn't supported by any version of zlib.)

The gzip header starts with hexadecimal 1F 8B. That isn't present in your data either.

So, I'm not sure what this data is, but it's neither gzip nor zlib data. You'll need to do some more research to figure out what it is.