Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s2: Fix final emit oob read crash on amd64 #601

Merged
merged 1 commit into from May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 24 additions & 13 deletions s2/_generate/gen.go
Expand Up @@ -727,19 +727,25 @@ func (o options) genEncodeBlockAsm(name string, tableBits, skipLog, hashBytes, m
RET()
Label("emit_remainder_ok_" + name)
}
// emitLiteral(dst[d:], src[nextEmitL:])
emitEnd := GP64()
MOVQ(lenSrcQ, emitEnd)

// Emit final literals.
o.emitLiteralsDstP(nextEmitL, emitEnd, src, dst, "emit_remainder_"+name)

// Assert size is < limit
assert(func(ok LabelRef) {
// if dstBaseQ < dstLimitPtrQ: ok
CMPQ(dst, dstLimitPtrQ)
JL(ok)
})
{
// emitLiteral(dst[d:], src[nextEmitL:])
emitEnd := GP64()
MOVQ(lenSrcQ, emitEnd)

// Emit final literals.
// Since we may be at the end of source,
// we cannot have output margin.
x := o.outputMargin
o.outputMargin = 0
o.emitLiteralsDstP(nextEmitL, emitEnd, src, dst, "emit_remainder_"+name)
o.outputMargin = x
// Assert size is < limit
assert(func(ok LabelRef) {
// if dstBaseQ < dstLimitPtrQ: ok
CMPQ(dst, dstLimitPtrQ)
JL(ok)
})
}

// length := start - base (ptr arithmetic)
length := GP64()
Expand Down Expand Up @@ -1437,7 +1443,12 @@ func (o options) genEncodeBetterBlockAsm(name string, lTableBits, skipLog, lHash
MOVQ(lenSrcQ, emitEnd)

// Emit final literals.
// Since we may be at the end of source,
// we cannot have output margin.
x := o.outputMargin
o.outputMargin = 0
o.emitLiteralsDstP(nextEmitL, emitEnd, src, dst, "emit_remainder_"+name)
o.outputMargin = x

// Assert size is < limit
assert(func(ok LabelRef) {
Expand Down