Finalize slurped JSON files when EOF follows a full read buffer (#3686)
When the size of a file was an exact multiple of the read buffer, the parser was never told that the input had ended. Pass the final empty read to the parser so that it finalizes at EOF. This makes `--slurpfile` and JSON data imports keep a trailing number or literal and report truncated JSON as an error, regardless of the file size.
This commit is contained in:
1 parent
629622d099
commit
3566cd366f
2 files changed
+14
-3
No files matched your search
+1
-3
@@ -46,12 +46,10 @@ jv jv_load_file(const char* filename, int raw) {
|
||||
int at_file_start = 1;
|
||||
while (!feof(file) && !ferror(file)) {
|
||||
size_t n = fread(buf, 1, sizeof(buf) - 4, file);
|
||||
if (n == 0)
|
||||
continue;
|
||||
|
||||
char *end = buf + n;
|
||||
int len = 0;
|
||||
if (jvp_utf8_backtrack(end - 1, buf, &len) && len > 0 &&
|
||||
if (n > 0 && jvp_utf8_backtrack(end - 1, buf, &len) && len > 0 &&
|
||||
!feof(file) && !ferror(file)) {
|
||||
n += fread(end, 1, len, file);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user