Zlib::DataError: incorrect header check
impythonista opened this issue · comments
I am facing Zlib::DataError: incorrect header check error for few strings. I got stuck into this issue, so please fix this asap.
I am getting exception only for few compressed string, please find example string in console:
ruby-1.9.3-p125> str = "eMKcK0ktLgEABF0Bw4E="
=> "eMKcK0ktLgEABF0Bw4E="
ruby-1.9.3-p125> Zlib::Inflate.inflate(str.unpack('m').first)
Zlib::DataError: incorrect header check
from (irb):3:in `inflate'
Could you please be a bit more specific? When and where are you getting this error? What request causes it?
When I compress the string using Juvia.compress function and going to decompress it in controller then I face this error.
You tried to compress the string "test". The correct result is:
Juvia.compress("test") == "eJwrSS0uAQAEXQHB"
Lets have a look at the base64 decoded values:
>> "eJwrSS0uAQAEXQHB".unpack("m")[0]
=> "x\x9C+I-.\x01\x00\x04]\x01\xC1"
>> "eMKcK0ktLgEABF0Bw4E=".unpack("m")[0]
=> "x\xC2\x9C+I-.\x01\x00\x04]\x01\xC3\x81"
Looks good apart from some strange characters:
>> "eMKcK0ktLgEABF0Bw4E=".unpack("m")[0].unpack("U*").pack("C*")
=> "x\x9C+I-.\x01\x00\x04]\x01\xC1"
So it looks your Base64.encode function interpreted the arguments as utf-8 string, not as "binary" string. My guess is your site includes a different Base64.encode that overwrote the one from juvia.