diff --git a/programs/util.c b/programs/util.c index 652530b1223..1f61520b857 100644 --- a/programs/util.c +++ b/programs/util.c @@ -730,6 +730,13 @@ static const char** UTIL_createLinePointers(char* buffer, size_t numLines, size_ len++; } + /* Drop a trailing '\r' so lists written with Windows-native CRLF + * endings (e.g. `dir /b > list.txt`) resolve. The file is opened in + * binary mode, so the C runtime does not strip it for us. */ + if (len > 0 && buffer[pos + len - 1] == '\r') { + buffer[pos + len - 1] = '\0'; + } + /* Move past this string and its null terminator */ pos += len; if (pos < bufferSize) pos++; /* Skip the null terminator if we're not at buffer end */ diff --git a/tests/playTests.sh b/tests/playTests.sh index d8ea0c3dad3..f00539d2b06 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -800,6 +800,13 @@ zstd -f --filelist=tmp_symLink test -f tmp2.zst test -f tmp1.zst +println "test : file list with Windows CRLF line endings, --filelist=FILE" +rm -f *.zst +printf 'tmp1\r\ntmp2\r\n' > tmp_crlfList +zstd -f --filelist=tmp_crlfList +test -f tmp1.zst +test -f tmp2.zst + println "test : compress multiple files reading them from multiple files, --filelist=FILE" rm -f *.zst println "Hello world!, file3" > tmp3