Skip to content

Commit

Permalink
Fix decoding of old bit stream
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Jul 30, 2022
1 parent 76bcbf8 commit bf2b078
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions java/src/main/java/kanzi/transform/ROLZCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ else if ((src[input.index+4] & 0x06) == 0x04)
ibs.close();
}

final int n = Math.min(dstEnd-dstIdx, 8);
final int n = (bsVersion < 3) ? 2 : Math.min(dstEnd-dstIdx, 8);

for (int j=0; j<n; j++)
dst[dstIdx++] = litBuf.array[litBuf.index++];
Expand Down Expand Up @@ -888,16 +888,16 @@ public boolean inverse(SliceByteArray input, SliceByteArray output)
int sizeChunk = Math.min(szBlock, CHUNK_SIZE);
int startChunk = output.index;
this.minMatch = MIN_MATCH3;
int srcIdx = input.index + 4;
final int bsVersion = (this.ctx == null) ? 3 : (Integer) this.ctx.getOrDefault("bsVersion", 3);

if (bsVersion >= 3)
{
if (src[input.index+4] == 1)
if (src[srcIdx++] == 1)
this.minMatch = MIN_MATCH7;
}

final int mm = this.minMatch;
int srcIdx = input.index + 5;
SliceByteArray sba = new SliceByteArray(src, srcIdx);
ROLZDecoder rd = new ROLZDecoder(9, this.logPosChecks, sba);

Expand All @@ -914,7 +914,7 @@ public boolean inverse(SliceByteArray input, SliceByteArray output)
int dstIdx = output.index;

// First literals
final int n = Math.min(dstEnd-startChunk, 8);
final int n = (bsVersion < 3) ? 2 : Math.min(dstEnd-startChunk, 8);
rd.setContext(LITERAL_CTX, (byte) 0);

for (int j=0; j<n; j++)
Expand All @@ -925,7 +925,7 @@ public boolean inverse(SliceByteArray input, SliceByteArray output)
if ((val1>>>8) == MATCH_FLAG)
{
output.index = dstIdx;
break;
return false;
}

dst[dstIdx++] = (byte) val1;
Expand Down Expand Up @@ -954,7 +954,7 @@ public boolean inverse(SliceByteArray input, SliceByteArray output)
if (dstIdx+matchLen+3 > dstEnd)
{
output.index = dstIdx;
break;
return false;
}

rd.setContext(MATCH_CTX, dst[dstIdx-1]);
Expand Down

0 comments on commit bf2b078

Please sign in to comment.