[Scummvm-git-logs] scummvm master -> 34983d1017ecf04b262ef1ac0e7f5c2b59607827

sluicebox noreply at scummvm.org
Wed May 18 18:28:30 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
34983d1017 SCI: Fix out of bounds read when measuring text


Commit: 34983d1017ecf04b262ef1ac0e7f5c2b59607827
    https://github.com/scummvm/scummvm/commit/34983d1017ecf04b262ef1ac0e7f5c2b59607827
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2022-05-18T14:26:06-04:00

Commit Message:
SCI: Fix out of bounds read when measuring text

Found with valgrind. The OOB read did not affect behavior.
Introduced in 8a87d1030c706db7fede0b5ece0aeabdf1a671cb

Changed paths:
    engines/sci/graphics/text16.cpp


diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp
index c137c5ff09f..b6a930bbd08 100644
--- a/engines/sci/graphics/text16.cpp
+++ b/engines/sci/graphics/text16.cpp
@@ -211,11 +211,10 @@ int16 GfxText16::GetLongest(const char *&textPtr, int16 maxWidth, GuiResourceId
 		curChar = (*(const byte *)textPtr);
 		if (_font->isDoubleByte(curChar)) {
 			curChar |= (*(const byte *)(textPtr + 1)) << 8;
-		}
-		if (escapedNewLine) {
+		} else if (escapedNewLine) {
 			escapedNewLine = false;
 			curChar = 0x0D;
-		} else if (isJapaneseNewLine(curChar, *(textPtr + 1))) {
+		} else if (curChar && isJapaneseNewLine(curChar, *(textPtr + 1))) {
 			escapedNewLine = true;
 			curChar = ' ';
 		}
@@ -391,11 +390,10 @@ void GfxText16::Width(const char *text, int16 from, int16 len, GuiResourceId org
 			if (_font->isDoubleByte(curChar)) {
 				curChar |= (*(const byte *)text++) << 8;
 				len--;
-			}
-			if (escapedNewLine) {
+			} else if (escapedNewLine) {
 				escapedNewLine = false;
 				curChar = 0x0D;
-			} else if (isJapaneseNewLine(curChar, *text)) {
+			} else if (curChar && isJapaneseNewLine(curChar, *text)) {
 				escapedNewLine = true;
 				curChar = ' ';
 			}
@@ -513,11 +511,10 @@ void GfxText16::Draw(const char *text, int16 from, int16 len, GuiResourceId orgF
 		if (_font->isDoubleByte(curChar)) {
 			curChar |= (*(const byte *)text++) << 8;
 			len--;
-		}
-		if (escapedNewLine) {
+		} else if (escapedNewLine) {
 			escapedNewLine = false;
 			curChar = 0x0D;
-		} else if (isJapaneseNewLine(curChar, *text)) {
+		} else if (curChar && isJapaneseNewLine(curChar, *text)) {
 			escapedNewLine = true;
 			curChar = ' ';
 		}




More information about the Scummvm-git-logs mailing list