aboutsummaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorLei Zhang <leizleiz@users.noreply.github.com>2016-10-19 14:47:17 -0700
committerLei Zhang <leizleiz@users.noreply.github.com>2016-10-19 14:47:17 -0700
commit1fba3b37c98301e2c01a5a3a7a87693ecdf4b4c8 (patch)
tree4ef458f6edcbdde2810b6c664471f45f805bc0ff /cpp
parent083b02b10572142d9863d945a8cf52fed2df997d (diff)
downloadsfntly-1fba3b37c98301e2c01a5a3a7a87693ecdf4b4c8.tar.gz
Fix undefined shifts in ReadableFontData::ReadLong.
Fixes https://crbug.com/646300
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/sfntly/data/readable_font_data.cc25
-rw-r--r--cpp/src/sfntly/data/readable_font_data.h9
2 files changed, 26 insertions, 8 deletions
diff --git a/cpp/src/sfntly/data/readable_font_data.cc b/cpp/src/sfntly/data/readable_font_data.cc
index df33f9a..93678ff 100644
--- a/cpp/src/sfntly/data/readable_font_data.cc
+++ b/cpp/src/sfntly/data/readable_font_data.cc
@@ -170,10 +170,19 @@ int64_t ReadableFontData::ReadULongLE(int32_t index) {
}
int32_t ReadableFontData::ReadLong(int32_t index) {
- return ReadByte(index) << 24 |
- ReadUByte(index + 1) << 16 |
- ReadUByte(index + 2) << 8 |
- ReadUByte(index + 3);
+ int32_t b1 = ReadByte(index);
+ if (b1 == kInvalidByte)
+ return kInvalidLong;
+ int32_t b2 = ReadUByte(index + 1);
+ if (b2 < 0)
+ return kInvalidLong;
+ int32_t b3 = ReadUByte(index + 2);
+ if (b3 < 0)
+ return kInvalidLong;
+ int32_t b4 = ReadUByte(index + 3);
+ if (b4 < 0)
+ return kInvalidLong;
+ return static_cast<uint32_t>(b1) << 24 | b2 << 16 | b3 << 8 | b4;
}
int32_t ReadableFontData::ReadFixed(int32_t index) {
@@ -181,7 +190,13 @@ int32_t ReadableFontData::ReadFixed(int32_t index) {
}
int64_t ReadableFontData::ReadDateTimeAsLong(int32_t index) {
- return (int64_t)ReadULong(index) << 32 | ReadULong(index + 4);
+ int32_t high = ReadULong(index);
+ if (high == kInvalidUnsigned)
+ return kInvalidLongDateTime;
+ int32_t low = ReadULong(index + 4);
+ if (low == kInvalidUnsigned)
+ return kInvalidLongDateTime;
+ return (int64_t)high << 32 | low;
}
int32_t ReadableFontData::ReadFWord(int32_t index) {
diff --git a/cpp/src/sfntly/data/readable_font_data.h b/cpp/src/sfntly/data/readable_font_data.h
index 003d494..37a0918 100644
--- a/cpp/src/sfntly/data/readable_font_data.h
+++ b/cpp/src/sfntly/data/readable_font_data.h
@@ -53,7 +53,9 @@ class ReadableFontData : public FontData,
static const int32_t kInvalidByte = 128;
static const int32_t kInvalidShort = 32768;
+ static const int32_t kInvalidLong = 0xffffffff;
static const int32_t kInvalidUnsigned = -1;
+ static const int64_t kInvalidLongDateTime = -1;
static CALLER_ATTACH ReadableFontData* CreateReadableFontData(ByteVector* b);
@@ -122,7 +124,7 @@ class ReadableFontData : public FontData,
// Read the ULONG at the given index.
// @param index index into the font data
- // @return the ULONG
+ // @return the ULONG; kInvalidUnsigned if outside the bounds of the font data
// @throws IndexOutOfBoundsException if index is outside the FontData's range
virtual int64_t ReadULong(int32_t index);
@@ -140,7 +142,7 @@ class ReadableFontData : public FontData,
// Read the LONG at the given index.
// @param index index into the font data
- // @return the LONG
+ // @return the LONG; kInvalidLong if outside the bounds of the font data
// @throws IndexOutOfBoundsException if index is outside the FontData's range
virtual int32_t ReadLong(int32_t index);
@@ -152,7 +154,8 @@ class ReadableFontData : public FontData,
// Read the LONGDATETIME at the given index.
// @param index index into the font data
- // @return the LONGDATETIME
+ // @return the LONGDATETIME; kInvalidLongDateTime if outside the bounds of the
+ // font data
// @throws IndexOutOfBoundsException if index is outside the FontData's range
virtual int64_t ReadDateTimeAsLong(int32_t index);