Skip to content

Commit

Permalink
internal/lz4block: Detect match with no space for offset
Browse files Browse the repository at this point in the history
This corner case wasn't detected by any of the decoders.
  • Loading branch information
greatroar authored and lizthegrey committed May 14, 2022
1 parent 0c17641 commit 72f1f00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions decode_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ copyLiteralFinish:
MOVB.NE tmp2, -1(dst)

copyLiteralDone:
CMP src, srcend
BEQ end

// Initial part of match length.
// This frees up the token register for reuse as offset.
AND $15, token, len

CMP src, srcend
BEQ end

// Read offset.
ADD.S $2, src
BCS shortSrc
Expand Down Expand Up @@ -188,6 +188,8 @@ copyMatchDone:
BNE loop

end:
CMP $0, len
BNE corrupt
SUB dstorig, dst, tmp1
MOVW tmp1, ret+24(FP)
RET
Expand Down
8 changes: 6 additions & 2 deletions decode_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ copyLiteralShortEnd:
MOVB.P tmp4, 1(dst)

copyLiteralDone:
// Initial part of match length.
AND $15, token, len

CMP src, srcend
BEQ end

Expand All @@ -123,8 +126,7 @@ copyLiteralDone:
MOVHU -2(src), offset
CBZ offset, corrupt

// Read match length.
AND $15, token, len
// Read rest of match length.
CMP $15, len
BNE readMatchlenDone

Expand Down Expand Up @@ -170,6 +172,7 @@ copyMatchLoop8:

MOVD (match)(len), tmp2 // match+len == match+lenRem-8.
ADD lenRem, dst
MOVD $0, len
MOVD tmp2, -8(dst)
B copyMatchDone

Expand All @@ -185,6 +188,7 @@ copyMatchDone:
BNE loop

end:
CBNZ len, corrupt
SUB dstorig, dst, tmp1
MOVD tmp1, ret+48(FP)
RET
Expand Down

0 comments on commit 72f1f00

Please sign in to comment.