From 7a24a4285c342ca5dea9a3b3fe176c4348aa9a51 Mon Sep 17 00:00:00 2001 From: Christopher Dannemiller Date: Tue, 21 May 2019 14:56:56 -0700 Subject: Fix a buffer overrun that can occur when the last byte of the file is '\r' or '\n' and the by adjacent to the last character in the file in memory is '\r' or '\n'. (#969) --- source/slang/source-loc.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source/slang/source-loc.cpp') diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp index b67426053..c66fdedb5 100644 --- a/source/slang/source-loc.cpp +++ b/source/slang/source-loc.cpp @@ -234,9 +234,13 @@ const List& SourceFile::getLineBreakOffsets() // where a multi-byte sequence might encode // the line break. - int d = *cursor; - if ((c^d) == ('\r' ^ '\n')) - cursor++; + // Check to make sure that the EOF hasn't been reached. + if (cursor != end) + { + int d = *cursor; + if ((c ^ d) == ('\r' ^ '\n')) + cursor++; + } m_lineBreakOffsets.add(uint32_t(cursor - begin)); break; -- cgit v1.2.3