Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[programs] Fix infinite loop when empty input is passed to trainer #3081

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion programs/dibio.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ static int DiB_loadFiles(
while ( nbSamplesLoaded < sstSize && fileIndex < nbFiles ) {
size_t fileDataLoaded;
S64 const fileSize = DiB_getFileSize(fileNamesTable[fileIndex]);
if (fileSize <= 0) /* skip if zero-size or file error */
if (fileSize <= 0) {
/* skip if zero-size or file error */
++fileIndex;
continue;
}

f = fopen( fileNamesTable[fileIndex], "rb");
if (f == NULL)
Expand Down
9 changes: 9 additions & 0 deletions tests/cli-tests/dict-builder/empty-input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e
for i in $(seq 50); do
datagen -s$i > file$i
done
touch empty

set -v
zstd -q --train empty file*
1 change: 1 addition & 0 deletions tests/cli-tests/dict-builder/empty-input.sh.stderr.exact
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zstd -q --train empty file*