aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmin Hassani <ahassani@google.com>2018-02-22 14:32:43 -0800
committerAmin Hassani <ahassani@google.com>2018-02-22 18:46:29 -0800
commit06c3d5304fe58884698b41bede7305a685207642 (patch)
tree6eae1775b7c95cad0f042f62d1baf067bf2dd8ce
parent8ae416c7e73a78c688178b51de1cae7a7a686f6d (diff)
downloadplatform_external_puffin-06c3d5304fe58884698b41bede7305a685207642.tar.gz
platform_external_puffin-06c3d5304fe58884698b41bede7305a685207642.tar.bz2
platform_external_puffin-06c3d5304fe58884698b41bede7305a685207642.zip
Fix a bug in PuffinStream
PuffinStream occasionally bitwise 'and' a 64 bit integer with the one's complement of a 32bit integer. This is a problem as the 32 MSBs of the one's complement number will become zero after implicit casting to 64bit integer. Bug:73781483 Test: unittests pass Test: puffhuff on a >5G file passes Change-Id: I4cccee9ac28f02ac81349c4ca3436c347f15cfb9
-rw-r--r--src/puffin_stream.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/puffin_stream.cc b/src/puffin_stream.cc
index e26e2c9..3fb54a1 100644
--- a/src/puffin_stream.cc
+++ b/src/puffin_stream.cc
@@ -334,7 +334,7 @@ bool PuffinStream::Write(const void* buffer, size_t length) {
auto bytes = static_cast<const uint8_t*>(buffer);
size_t bytes_wrote = 0;
while (bytes_wrote < length) {
- if (deflate_bit_pos_ < (cur_deflate_->offset & ~7u)) {
+ if (deflate_bit_pos_ < (cur_deflate_->offset & ~7ull)) {
// Between two puffs or before the first puff. We know that we are
// starting from the byte boundary because we have already processed the
// non-deflate bits of the last byte of the last deflate. Here we don't
@@ -397,7 +397,7 @@ bool PuffinStream::Write(const void* buffer, size_t length) {
if (extra_byte_ == 1) {
deflate_buffer_->data()[bytes_to_write - 1] |=
puff_buffer_->data()[cur_puff_->length] << (deflate_bit_pos_ & 7);
- deflate_bit_pos_ = (deflate_bit_pos_ + 7) & ~7u;
+ deflate_bit_pos_ = (deflate_bit_pos_ + 7) & ~7ull;
} else if ((deflate_bit_pos_ & 7) != 0) {
// This happens if current and next deflate finish and end on the same
// byte, then we cannot write into output until we have huffed the
@@ -436,7 +436,7 @@ bool PuffinStream::SetExtraByte() {
return true;
}
size_t end_bit = cur_deflate_->offset + cur_deflate_->length;
- if ((end_bit & 7) && ((end_bit + 7) & ~7u) <= (cur_deflate_ + 1)->offset) {
+ if ((end_bit & 7) && ((end_bit + 7) & ~7ull) <= (cur_deflate_ + 1)->offset) {
extra_byte_ = 1;
} else {
extra_byte_ = 0;