File 0001-Added-bounds-checking-to-CDataMoji-in-jww-parser.patch of Package librecad.17497
From f3502963eaf379a429bc9da73c1224c5db649997 Mon Sep 17 00:00:00 2001
From: eldstal <laeder.keps@gmail.com>
Date: Sat, 18 Dec 2021 20:27:34 +0100
Subject: [PATCH] Added bounds checking to CDataMoji in jww parser.
This fixes issue #1462
---
libraries/jwwlib/src/jwwdoc.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/libraries/jwwlib/src/jwwdoc.h b/libraries/jwwlib/src/jwwdoc.h
index fc8cd217..a11bc63a 100644
--- a/libraries/jwwlib/src/jwwdoc.h
+++ b/libraries/jwwlib/src/jwwdoc.h
@@ -521,7 +521,17 @@ cout << "MojiData1:" << m_strFontName << endl;
}else
{
ifstr >> wd;
+
+ jwDWORD skip = 0;
+ if (wd > 511) {
+ skip = wd - 511;
+ wd = 511;
+ }
+
ifstr.read(buf,wd);
+
+ if (skip != 0) ifstr.ignore(skip);
+
buf[wd] = '\0';
m_strFontName = buf;
#ifdef DATA_DUMP
@@ -539,7 +549,17 @@ cout << "MojiData3:" << m_string << endl;
}else
{
ifstr >> wd;
+
+ jwDWORD skip = 0;
+ if (wd > 511) {
+ skip = wd - 511;
+ wd = 511;
+ }
+
ifstr.read(buf,wd);
+
+ if (skip != 0) ifstr.ignore(skip);
+
buf[wd] = '\0';
m_string = buf;
#ifdef DATA_DUMP
--
2.36.1