Normalizing PNGs: Zlib::BufError: buffer error #598

Closed
maxsz opened this Issue Mar 21, 2013 · 7 comments

Projects

None yet

4 participants

@maxsz
maxsz commented Mar 21, 2013

Intro

Apple uses some pre-compilation (basically byte swapping) on PNG files stored inside an iOS app. To reverse these changes, there exists code like this: https://github.com/swcai/iphone-png-normalizer/blob/master/iphonepng.rb. Running this particular script with MRI succeeds, but fails with JRuby for some images.

Error

Particularly with this image (Icon-114) I get the following error. Note that this image appears to be broken here, because of the byte swapping mentioned above. Also note that MRI (1.9.3) doesn't choke on it.

Zlib::BufError: buffer error
         finish at org/jruby/ext/zlib/ZStream.java:110
     decompress at normalizePNG.rb:28
      normalize at normalizePNG.rb:79
            map at org/jruby/RubyArray.java:2361
      normalize at normalizePNG.rb:76
  normalize_png at normalizePNG.rb:111
           open at org/jruby/RubyIO.java:1183
  normalize_png at normalizePNG.rb:110
         (root) at normalizePNG.rb:120
           each at org/jruby/RubyArray.java:1613
         (root) at normalizePNG.rb:120
           each at org/jruby/RubyArray.java:1613
         (root) at normalizePNG.rb:120
@BanzaiMan
Member

With which version of JRuby does the problem manifest?

Does this happen on all PNG files? The picture you indicated seems to be invalid. Is there another one we can try?

@maxsz
maxsz commented Mar 26, 2013

The problem occurs with JRuby 1.7.3 (haven't tried any other versions).

This does not happen with all PNG files. I know that the picture looks 'invalid', as I described above it has been pre-compiled by Xcode (see http://iphonedevelopment.blogspot.com/2008/10/iphone-optimized-pngs.html for more information), so it will look invalid to any other application. That is why I need to apply the normalizing in the first place. Again, MRI can handle this exact same image, while JRuby does not.

@BanzaiMan
Member

It works for me on 1.7.3 as well as master.

$ jruby -v; jruby iphonepng.rb 46c96086-9206-11e2-98d6-7b2bd33b1692.png
jruby 1.7.3 (1.9.3p385) 2013-03-26 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_13-b20 [darwin-x86_64]
Done.
$ jruby -v; jruby iphonepng.rb 46c96086-9206-11e2-98d6-7b2bd33b1692.png
jruby 1.7.4.dev (1.9.3p392) 2013-03-26 c94eb81 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_13-b20 [darwin-x86_64]
Done.

I wonder what might be causing you grief.

@maxsz
maxsz commented Mar 27, 2013

Oh, I'm sorry, I should have explained how that script works. It expects a folder as input. This should clarify things:

$ jruby -v; jruby iphonepng.rb 46c96086-9206-11e2-98d6-7b2bd33b1692.png
jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_43-b01-447-11M4203 [darwin-x86_64]
Done.
$ mkdir test
$ mv 46c96086-9206-11e2-98d6-7b2bd33b1692.png test
$ jruby -v; jruby iphonepng.rb test
jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_43-b01-447-11M4203 [darwin-x86_64]
test/46c96086-9206-11e2-98d6-7b2bd33b1692.png
Zlib::BufError: buffer error
         finish at org/jruby/ext/zlib/ZStream.java:110
     decompress at iphonepng.rb:28
      normalize at iphonepng.rb:79
            map at org/jruby/RubyArray.java:2361
      normalize at iphonepng.rb:76
  normalize_png at iphonepng.rb:111
           open at org/jruby/RubyIO.java:1183
  normalize_png at iphonepng.rb:110
         (root) at iphonepng.rb:120
           each at org/jruby/RubyArray.java:1613
         (root) at iphonepng.rb:120
           each at org/jruby/RubyArray.java:1613
         (root) at iphonepng.rb:120
$ ls -l
-rw-r--r--  1 szengel  staff  3235 Mar 27 11:45 iphonepng.rb
drwxr-xr-x  3 szengel  staff   102 Mar 27 11:46 test/
$ ls -l test
-rw-r--r--  1 szengel  staff  2794 Mar 21 10:04 46c96086-9206-11e2-98d6-7b2bd33b1692.png
@BanzaiMan
Member

Thanks. I confirmed the error.

@MSNexploder
Contributor

This still fails with JRuby 1.7.18

jruby 1.7.18 (1.9.3p551) 2014-12-22 625381c on Java HotSpot(TM) 64-Bit Server VM 1.8.0_25-b17 [darwin-x86_64]
test/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3534303032352f3238343931352f34366339363038362d393230362d313165322d393864362d3762326264333362313639322e706e67.png
Zlib::BufError: buffer error
         finish at org/jruby/ext/zlib/ZStream.java:134
     decompress at iphonepng.rb:28
      normalize at iphonepng.rb:79
        collect at org/jruby/RubyArray.java:2399
            map at org/jruby/RubyArray.java:2412
      normalize at iphonepng.rb:76
  normalize_png at iphonepng.rb:111
           open at org/jruby/RubyIO.java:1181
  normalize_png at iphonepng.rb:110
         (root) at iphonepng.rb:120
           each at org/jruby/RubyArray.java:1613
         (root) at iphonepng.rb:120
           each at org/jruby/RubyArray.java:1613
         (root) at iphonepng.rb:120

but works on master

jruby 9.0.0.0-SNAPSHOT (2.2.0p0) 2015-01-01 fb9199f Java HotSpot(TM) 64-Bit Server VM 25.25-b02 on 1.8.0_25-b17 +jit [darwin-x86_64]
test/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3534303032352f3238343931352f34366339363038362d393230362d313165322d393864362d3762326264333362313639322e706e67.png
Corrupted PNG file
Done.
@enebo enebo added the JRuby 1.7.x label Feb 17, 2017
@enebo enebo added this to the Won't Fix milestone Feb 17, 2017
@enebo
Member
enebo commented Feb 17, 2017

This works in 9k and we will never fix this in 1.7.x as it is winding down....resolving.

@enebo enebo closed this Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment