summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-05 14:49:09 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-05 14:50:17 +0100
commit5e95d62ffef98eec2164157174d182d8d8b538a4 (patch)
tree8c8ac57a851fa59d621865bd8048f4c2e76d04a0 /Libraries
parent688d249b2dad91b3b795a91604a56c8da93b3482 (diff)
downloadserenity-5e95d62ffef98eec2164157174d182d8d8b538a4.zip
LibTTF: Guard against unsigned overflow in TTF table parsing
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29170
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibTTF/Font.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/Libraries/LibTTF/Font.cpp b/Libraries/LibTTF/Font.cpp
index 69b3d1ee07..0e514b7be1 100644
--- a/Libraries/LibTTF/Font.cpp
+++ b/Libraries/LibTTF/Font.cpp
@@ -25,6 +25,7 @@
*/
#include "AK/ByteBuffer.h"
+#include <AK/Checked.h>
#include <AK/LogStream.h>
#include <AK/Utf32View.h>
#include <AK/Utf8View.h>
@@ -271,6 +272,12 @@ RefPtr<Font> Font::load_from_offset(ByteBuffer&& buffer, u32 offset)
u32 tag = be_u32(buffer.offset_pointer(record_offset));
u32 table_offset = be_u32(buffer.offset_pointer(record_offset + (u32)Offsets::TableRecord_Offset));
u32 table_length = be_u32(buffer.offset_pointer(record_offset + (u32)Offsets::TableRecord_Length));
+
+ if (Checked<u32>::addition_would_overflow(table_offset, table_length)) {
+ dbgln("Invalid table offset/length in font.");
+ return nullptr;
+ }
+
if (buffer.size() < table_offset + table_length) {
dbg() << "Font file too small";
return nullptr;