Index: third_party/woff2/src/woff2_common.cc |
diff --git a/third_party/woff2/src/woff2_common.cc b/third_party/woff2/src/woff2_common.cc |
index 39dc54e6f313cff062d924bfb2d29ddbaa2fc267..eba6a46e213980d55a90bc0101702dea64c67a4e 100644 |
--- a/third_party/woff2/src/woff2_common.cc |
+++ b/third_party/woff2/src/woff2_common.cc |
@@ -23,7 +23,8 @@ namespace woff2 { |
uint32_t ComputeULongSum(const uint8_t* buf, size_t size) { |
uint32_t checksum = 0; |
- for (size_t i = 0; i < size; i += 4) { |
+ size_t aligned_size = size & ~3; |
+ for (size_t i = 0; i < aligned_size; i += 4) { |
#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) |
uint32_t v = *reinterpret_cast<const uint32_t*>(buf + i); |
checksum += (((v & 0xFF) << 24) | ((v & 0xFF00) << 8) | |
@@ -35,6 +36,16 @@ uint32_t ComputeULongSum(const uint8_t* buf, size_t size) { |
(buf[i + 2] << 8) | buf[i + 3]; |
#endif |
} |
+ |
+ // treat size not aligned on 4 as if it were padded to 4 with 0's |
+ if (size != aligned_size) { |
+ uint32_t v = 0; |
+ for (size_t i = aligned_size; i < size; ++i) { |
+ v |= buf[i] << (24 - 8 * (i & 3)); |
+ } |
+ checksum += v; |
+ } |
+ |
return checksum; |
} |