Skip to content

Commit

Permalink
zstd: fix Go implementation
Browse files Browse the repository at this point in the history
Print the correct size of output in error message in the case of output overflow.
  • Loading branch information
WojciechMula committed Apr 22, 2022
1 parent 8eb85f1 commit 88518c9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions zstd/seqdec.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (s *sequenceDecs) decodeSync(hist []byte) error {
}
size := ll + ml + len(out)
if size-startSize > maxBlockSize {
return fmt.Errorf("output (%d) bigger than max block size (%d)", size, maxBlockSize)
return fmt.Errorf("output (%d) bigger than max block size (%d)", size-startSize, maxBlockSize)
}
if size > cap(out) {
// Not enough size, which can happen under high volume block streaming conditions
Expand Down Expand Up @@ -409,8 +409,8 @@ func (s *sequenceDecs) decodeSync(hist []byte) error {
}

// Check if space for literals
if len(s.literals)+len(s.out)-startSize > maxBlockSize {
return fmt.Errorf("output (%d) bigger than max block size (%d)", len(s.out), maxBlockSize)
if size := len(s.literals) + len(s.out) - startSize; size > maxBlockSize {
return fmt.Errorf("output (%d) bigger than max block size (%d)", size, maxBlockSize)
}

// Add final literals
Expand Down

0 comments on commit 88518c9

Please sign in to comment.