[LTP] [PATCH v2 03/15] ujson: reader: Prevent infinite loop on EOF

Andrea Cervesato andrea.cervesato@suse.de
Tue Oct 13 14:01:59 CEST 2026


From: Andrea Cervesato <andrea.cervesato@suse.com>

When read() returns 0 before reaching the size reported by lseek()
(e.g. truncated files), off does not advance and the loop spins
indefinitely. Treat premature EOF as an error and fail the load.

Fixes: c50a0e0751c8 ("libs: Vendor ujson library")
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 libs/ujson/ujson_reader.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libs/ujson/ujson_reader.c b/libs/ujson/ujson_reader.c
index 9f86f25b7..3cd7fcce5 100644
--- a/libs/ujson/ujson_reader.c
+++ b/libs/ujson/ujson_reader.c
@@ -1032,6 +1032,11 @@ ujson_reader *ujson_reader_load(const char *path)
 			goto err1;
 		}
 
+		if (res == 0) {
+			fprintf(stderr, "read() returned 0 (file was truncated?)\n");
+			goto err1;
+		}
+
 		off += res;
 	}
 

-- 
2.51.0



More information about the ltp mailing list