| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/utility/safe_browsing/mac/udif.h" | 5 #include "chrome/utility/safe_browsing/mac/udif.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #include <bzlib.h> | 8 #include <bzlib.h> |
| 9 #include <libkern/OSByteOrder.h> | 9 #include <libkern/OSByteOrder.h> |
| 10 #include <uuid/uuid.h> | 10 #include <uuid/uuid.h> |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 if (!decompress_read_offset.IsValid()) { | 647 if (!decompress_read_offset.IsValid()) { |
| 648 DLOG(ERROR) << "Partition decompress read offset overflows"; | 648 DLOG(ERROR) << "Partition decompress read offset overflows"; |
| 649 return -1; | 649 return -1; |
| 650 } | 650 } |
| 651 | 651 |
| 652 if (!chunk_stream_ || chunk != chunk_stream_->chunk()) { | 652 if (!chunk_stream_ || chunk != chunk_stream_->chunk()) { |
| 653 chunk_stream_.reset( | 653 chunk_stream_.reset( |
| 654 new UDIFBlockChunkReadStream(stream_, block_size_, chunk)); | 654 new UDIFBlockChunkReadStream(stream_, block_size_, chunk)); |
| 655 } | 655 } |
| 656 current_chunk_ = chunk_number; | 656 current_chunk_ = chunk_number; |
| 657 chunk_stream_->Seek(decompress_read_offset.ValueOrDie(), SEEK_SET); | 657 if (chunk_stream_->Seek(decompress_read_offset.ValueOrDie(), SEEK_SET) == -1) |
| 658 return -1; |
| 658 | 659 |
| 659 return offset; | 660 return offset; |
| 660 } | 661 } |
| 661 | 662 |
| 662 UDIFBlockChunkReadStream::UDIFBlockChunkReadStream(ReadStream* stream, | 663 UDIFBlockChunkReadStream::UDIFBlockChunkReadStream(ReadStream* stream, |
| 663 uint16_t block_size, | 664 uint16_t block_size, |
| 664 const UDIFBlockChunk* chunk) | 665 const UDIFBlockChunk* chunk) |
| 665 : stream_(stream), | 666 : stream_(stream), |
| 666 chunk_(chunk), | 667 chunk_(chunk), |
| 667 length_in_bytes_(chunk->sector_count * block_size), | 668 length_in_bytes_(chunk->sector_count * block_size), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 695 break; | 696 break; |
| 696 case UDIFBlockChunk::Type::LAST_BLOCK: | 697 case UDIFBlockChunk::Type::LAST_BLOCK: |
| 697 *bytes_read = 0; | 698 *bytes_read = 0; |
| 698 return true; | 699 return true; |
| 699 } | 700 } |
| 700 return false; | 701 return false; |
| 701 } | 702 } |
| 702 | 703 |
| 703 off_t UDIFBlockChunkReadStream::Seek(off_t offset, int whence) { | 704 off_t UDIFBlockChunkReadStream::Seek(off_t offset, int whence) { |
| 704 DCHECK_EQ(SEEK_SET, whence); | 705 DCHECK_EQ(SEEK_SET, whence); |
| 705 DCHECK_LT(static_cast<uint64_t>(offset), length_in_bytes_); | 706 if (static_cast<uint64_t>(offset) >= length_in_bytes_) |
| 707 return -1; |
| 706 offset_ = offset; | 708 offset_ = offset; |
| 707 return offset_; | 709 return offset_; |
| 708 } | 710 } |
| 709 | 711 |
| 710 bool UDIFBlockChunkReadStream::CopyOutZeros(uint8_t* buffer, | 712 bool UDIFBlockChunkReadStream::CopyOutZeros(uint8_t* buffer, |
| 711 size_t buffer_size, | 713 size_t buffer_size, |
| 712 size_t* bytes_read) { | 714 size_t* bytes_read) { |
| 713 *bytes_read = std::min(buffer_size, length_in_bytes_ - offset_); | 715 *bytes_read = std::min(buffer_size, length_in_bytes_ - offset_); |
| 714 bzero(buffer, *bytes_read); | 716 bzero(buffer, *bytes_read); |
| 715 offset_ += *bytes_read; | 717 offset_ += *bytes_read; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 << chunk_->compressed_offset; | 836 << chunk_->compressed_offset; |
| 835 return false; | 837 return false; |
| 836 } | 838 } |
| 837 return true; | 839 return true; |
| 838 } | 840 } |
| 839 | 841 |
| 840 } // namespace | 842 } // namespace |
| 841 | 843 |
| 842 } // namespace dmg | 844 } // namespace dmg |
| 843 } // namespace safe_browsing | 845 } // namespace safe_browsing |
| OLD | NEW |