aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-02-22 03:15:07 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-02-22 03:15:07 +0000
commit9f7b396b74ac0ff03bf7e7fdc08b4b38cef00279 (patch)
treec00a905e82383a0958dbd9f7fd3ab99c3ee573dc
parentf198694f772dd72dd92f360579bc4be8c50bfc30 (diff)
parentf41ef119872c6595e7711ca9346131eb8d40ac8f (diff)
downloadplatform_external_puffin-android11-gsi.tar.gz
platform_external_puffin-android11-gsi.tar.bz2
platform_external_puffin-android11-gsi.zip
Change-Id: Ibd849c77f03c09173f2e7885f906576c7c39534f
-rw-r--r--src/utils.cc26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/utils.cc b/src/utils.cc
index d0aece0..b9b06c1 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -7,6 +7,7 @@
#include <inttypes.h>
#include <algorithm>
+#include <iterator>
#include <set>
#include <string>
#include <vector>
@@ -176,16 +177,24 @@ bool LocateDeflatesInZlibBlocks(const string& file_path,
return true;
}
+namespace {
// For more information about gzip format, refer to RFC 1952 located at:
// https://www.ietf.org/rfc/rfc1952.txt
+bool IsValidGzipHeader(const uint8_t* header, size_t size) {
+ // Each gzip entry has the following format magic header:
+ // 0 1 0x1F
+ // 1 1 0x8B
+ // 2 1 compression method (8 denotes deflate)
+ static const uint8_t magic[] = {0x1F, 0x8B, 8};
+ return size >= 10 && std::equal(std::begin(magic), std::end(magic), header);
+}
+} // namespace
+
bool LocateDeflatesInGzip(const Buffer& data, vector<BitExtent>* deflates) {
+ TEST_AND_RETURN_FALSE(IsValidGzipHeader(data.data(), data.size()));
uint64_t member_start = 0;
- while (member_start + 10 <= data.size() && data[member_start + 0] == 0x1F &&
- data[member_start + 1] == 0x8B && data[member_start + 2] == 8) {
- // Each member entry has the following format
- // 0 1 0x1F
- // 1 1 0x8B
- // 2 1 compression method (8 denotes deflate)
+ do {
+ // After the magic header, the gzip contains:
// 3 1 set of flags
// 4 4 modification time
// 8 1 extra flags
@@ -234,9 +243,8 @@ bool LocateDeflatesInGzip(const Buffer& data, vector<BitExtent>* deflates) {
TEST_AND_RETURN_FALSE(offset + 8 <= data.size());
offset += 8;
member_start = offset;
- }
- // Return true if we've successfully parsed at least one gzip.
- return member_start != 0;
+ } while (IsValidGzipHeader(&data[member_start], data.size() - member_start));
+ return true;
}
// For more information about the zip format, refer to