From d109cef2012b1e0ca7a6f47278a2838f68bbc196 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Sat, 5 Mar 2022 03:56:44 +0800 Subject: [PATCH] fix the assertion in readLinesFromFile (#3084) * fix the assertion in readLinesFromFile When the file is not terminated by endline, readLineFromFile will append a '\0' for the last line. In this case pos + lineLength == dstCapacity. * test: don't print very long text garbage --- programs/util.c | 2 +- tests/playTests.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/util.c b/programs/util.c index d69b72a37..55bcff25a 100644 --- a/programs/util.c +++ b/programs/util.c @@ -418,7 +418,7 @@ readLinesFromFile(void* dst, size_t dstCapacity, while ( !feof(inputFile) ) { size_t const lineLength = readLineFromFile(buf+pos, dstCapacity-pos, inputFile); if (lineLength == 0) break; - assert(pos + lineLength < dstCapacity); + assert(pos + lineLength <= dstCapacity); /* '=' for inputFile not terminated with '\n' */ pos += lineLength; ++nbFiles; } diff --git a/tests/playTests.sh b/tests/playTests.sh index 71e8dc058..d4271b2f0 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -735,11 +735,11 @@ test -f tmp4 println "test : survive the list of files with too long filenames (--filelist=FILE)" datagen -g5M > tmp_badList -zstd -f --filelist=tmp_badList && die "should have failed : file name length is too long" +zstd -qq -f --filelist=tmp_badList && die "should have failed : file name length is too long" # printing very long text garbage on console will cause CI failure println "test : survive a list of files which is text garbage (--filelist=FILE)" datagen > tmp_badList -zstd -f --filelist=tmp_badList && die "should have failed : list is text garbage" +zstd -qq -f --filelist=tmp_badList && die "should have failed : list is text garbage" # printing very long text garbage on console will cause CI failure println "test : survive a list of files which is binary garbage (--filelist=FILE)" datagen -P0 -g1M > tmp_badList