From b7cac2d38f517738528e4c0ff5cd62efc2b52d73 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 13 May 2020 20:19:45 -0600 Subject: [PATCH] Fix sliceAtEOF() bug causing short ANSI's to get borked when e.g. display achievements --- core/art.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/art.js b/core/art.js index 38594985..0ff4835f 100644 --- a/core/art.js +++ b/core/art.js @@ -49,7 +49,7 @@ function getFontNameFromSAUCE(sauce) { function sliceAtEOF(data, eofMarker) { let eof = data.length; - const stopPos = Math.max(data.length - (256), 0); // 256 = 2 * sizeof(SAUCE) + const stopPos = Math.max(data.length - 256, 0); // 256 = 2 * sizeof(SAUCE) for(let i = eof - 1; i > stopPos; i--) { if(eofMarker === data[i]) { @@ -57,9 +57,16 @@ function sliceAtEOF(data, eofMarker) { break; } } - if(eof === data.length || eof < 128) { + + if (eof === data.length) { + return data; // nothing to do + } + + // try to prevent goofs + if (eof < 128 && 'SAUCE00' !== data.slice(eof + 1, eof + 8).toString()) { return data; } + return data.slice(0, eof); }