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

bzip2: fix bug with duplicate read of CRC32 when it overlaps end of buffer and 'bzip2-done is thrown. #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions bzip2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,22 @@
(unless (= byte #x59)
(error 'invalid-bzip2-data))
(incf (bzip2-state-current-block-number state))
(transition-to bzip2-block-crc32)))
(transition-to bzip2-block-crc32-1)))

(bzip2-block-crc32 (state)
(bzip2-block-crc32-1 (state)
(declare (type bzip2-state state))
(let ((crc32-hi (ensure-and-read-bits 16 state))
;; store first part of CRC32
;; (the 2 states should be split to avoid bug when
;; the state machine is restarted between reads of the hi & lo parts)
(setf (bzip2-state-stored-block-crc state)
(ensure-and-read-bits 16 state))
(transition-to bzip2-block-crc32-2))

(bzip2-block-crc32-2 (state)
(declare (type bzip2-state state))
(let ((crc32-hi (bzip2-state-stored-block-crc state))
(crc32-lo (ensure-and-read-bits 16 state)))
;; combine first and second part of CRC32
(setf (bzip2-state-stored-block-crc state)
(logior (ash crc32-hi 16) crc32-lo))
(transition-to bzip2-block-randombit)))
Expand Down