blob: 1807dde181b4823ba0cfe055b3c35438be443c4a [file] [log] [blame]
Index: lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressionMode.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressionMode.java (revision 1648036)
+++ lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressionMode.java (working copy)
@@ -201,9 +201,7 @@
// pad with extra "dummy byte": see javadocs for using Inflater(true)
// we do it for compliance, but it's unnecessary for years in zlib.
final int paddedLength = compressedLength + 1;
- if (paddedLength > compressed.length) {
- compressed = new byte[ArrayUtil.oversize(paddedLength, 1)];
- }
+ compressed = ArrayUtil.grow(compressed, paddedLength);
in.readBytes(compressed, 0, compressedLength);
compressed[compressedLength] = 0; // explicitly set dummy byte to 0
@@ -212,21 +210,16 @@
decompressor.setInput(compressed, 0, paddedLength);
bytes.offset = bytes.length = 0;
- while (true) {
- final int count;
- try {
- final int remaining = bytes.bytes.length - bytes.length;
- count = decompressor.inflate(bytes.bytes, bytes.length, remaining);
- } catch (DataFormatException e) {
- throw new IOException(e);
- }
- bytes.length += count;
- if (decompressor.finished()) {
- break;
- } else {
- bytes.bytes = ArrayUtil.grow(bytes.bytes);
- }
+ bytes.bytes = ArrayUtil.grow(bytes.bytes, originalLength);
+ try {
+ bytes.length = decompressor.inflate(bytes.bytes, bytes.length, originalLength);
+ } catch (DataFormatException e) {
+ throw new IOException(e);
}
+ if (!decompressor.finished()) {
+ throw new CorruptIndexException("Invalid decoder state: needsInput=" + decompressor.needsInput()
+ + ", needsDict=" + decompressor.needsDictionary(), in);
+ }
if (bytes.length != originalLength) {
throw new CorruptIndexException("Lengths mismatch: " + bytes.length + " != " + originalLength, in);
}