Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JRUBY-4502: Wrong gzip data crashes JRuby (collab w/ nahi...thanks na…

…hi!)
  • Loading branch information...
commit 539f45c3e3c59ca9ec7970cf6e81f8500cc9b4d7 1 parent 3938c82
@enebo enebo authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/org/jruby/ext/zlib/RubyZlib.java
View
16 src/org/jruby/ext/zlib/RubyZlib.java
@@ -1343,13 +1343,27 @@ public Arity getArity() {
}
return obj;
}
+
+ /**
+ * Get position within this stream including that has been read by
+ * users calling read + what jzlib may have speculatively read in
+ * because of buffering.
+ * @return number of bytes
+ */
+ private long internalPosition() {
+ long n = io.getTotalIn();
+
+ if (io.getAvailIn() != null) n += io.getAvailIn().length;
+
+ return n;
+ }
@JRubyMethod
public IRubyObject rewind() {
Ruby rt = getRuntime();
// should invoke seek on realIo...
realIo.callMethod(rt.getCurrentContext(), "seek",
- new IRubyObject[]{rt.newFixnum(-io.getTotalIn()), rt.newFixnum(Stream.SEEK_CUR)});
+ new IRubyObject[]{rt.newFixnum(-internalPosition()), rt.newFixnum(Stream.SEEK_CUR)});
// ... and then reinitialize
initialize(realIo);
return getRuntime().getNil();
Please sign in to comment.
Something went wrong with that request. Please try again.