All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 00/15] Fix ujson bugs
@ 2026-10-13 12:01 Andrea Cervesato
  2026-10-13 12:01 ` [LTP] [PATCH v2 01/15] ujson: Fix 4-byte UTF-8 sequence decoding Andrea Cervesato
                   ` (14 more replies)
  0 siblings, 15 replies; 18+ messages in thread
From: Andrea Cervesato @ 2026-10-13 12:01 UTC (permalink / raw)
  To: Linux Test Project

- fix 4-byte UTF-8 sequence decoding in ujson_utf8_next()
- fix out-of-bounds read on invalid UTF-8 in ujson_writer
- prevent infinite loop when read() returns 0 in ujson_reader
- fix inverted open() error check in ujson_writer_file_open()
- return UTF-8 length when calculating string size in ujson_reader
- combine UTF-16 surrogate pairs and reject lone surrogates
- check for signed integer overflow when parsing numbers
- fix error propagation when newline() fails in ujson_writer
- check output return values in esc_flush() helper
- unescape object IDs and reset type on error in ujson_reader
- reject empty and zero-sized files in ujson_reader_load()
- reject \u0000 escape sequences in string values
- set errno when a file flush fails in ujson_writer
- advance buffer pointer on short write in ujson_writer
- flush buffered data before direct writes in ujson_writer

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v2:
- ujson: reader: Prevent infinite loop on EOF: fail load on premature
  EOF instead of accepting truncated file.
- ujson: reader: Return UTF-8 length when !str: split out UTF-8 length
  calculation when !str into separate commit before surrogate handling.
- ujson: reader: Combine UTF-16 surrogate pairs: reorder checks to
  inspect unpaired low surrogates first.
- ujson: reader: Check for signed integer overflow: assign negative
  integers with -(long)val.
- ujson: writer: Check return value in esc_flush(): replace ESC_FLUSH
  macro with esc_flush() helper function and check return values.
- ujson: reader: Do not increment depth on overflow: dropped from
  series.
- ujson: reader: Parse escape sequences in object IDs: reset res->type
  to UJSON_VOID on key parsing failure.
- ujson: reader: Reject files with zero size: reject zero-sized and
  empty files in ujson_reader_load() instead of dynamic reallocation.
- ujson: writer: Set errno when a flush fails: distinguish ret == 0
  with a dedicated error message and errno = EAGAIN.
- ujson: writer: Flush buffer before direct writes: move !buf_len
  check into out_writer_file_write().
- Link to v1: https://lore.kernel.org/20261005-fix_core_lib_deepseek-v1-0-fec334ce8e80@suse.com

---
Andrea Cervesato (15):
      ujson: Fix 4-byte UTF-8 sequence decoding
      ujson: writer: Fix OOB read on invalid UTF-8
      ujson: reader: Prevent infinite loop on EOF
      ujson: writer: Fix open() return value check
      ujson: reader: Return UTF-8 length when !str
      ujson: reader: Combine UTF-16 surrogate pairs
      ujson: reader: Check for signed integer overflow
      ujson: writer: Return error when newline() fails
      ujson: writer: Check return value in esc_flush()
      ujson: reader: Parse escape sequences in object IDs
      ujson: reader: Reject files with zero size
      ujson: reader: Reject \u0000 escape in strings
      ujson: writer: Set errno when a flush fails
      ujson: writer: Advance buffer on short write
      ujson: writer: Flush buffer before direct writes

 include/ujson_utf.h       |   6 +--
 libs/ujson/ujson_reader.c | 101 ++++++++++++++++++++++++++++++++--------------
 libs/ujson/ujson_writer.c |  75 ++++++++++++++++++++++++----------
 3 files changed, 126 insertions(+), 56 deletions(-)
---
base-commit: 07da37cf3dbda876b33ad820168a33b9deacbddb
change-id: 20260925-fix_core_lib_deepseek-2ba9018c7588

Best regards,
--  
Andrea Cervesato <andrea.cervesato@suse.com>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 18+ messages in thread
* [LTP] [PATCH 03/15] ujson: reader: Prevent infinite loop on EOF
@ 2026-10-05 13:25 Andrea Cervesato
  2026-10-05 18:06 ` [LTP] ujson: Fix 4-byte UTF-8 sequence decoding linuxtestproject.agent
  0 siblings, 1 reply; 18+ messages in thread
From: Andrea Cervesato @ 2026-10-05 13:25 UTC (permalink / raw)
  To: Linux Test Project

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

When read() returns 0 before reaching the size reported by lseek()
(e.g. sysfs files or truncated files), off does not advance and the
loop spins indefinitely. Treat read() == 0 as EOF by breaking the loop
and updating the buffer length and terminator.

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

diff --git a/libs/ujson/ujson_reader.c b/libs/ujson/ujson_reader.c
index 9f86f25b7..2219c5801 100644
--- a/libs/ujson/ujson_reader.c
+++ b/libs/ujson/ujson_reader.c
@@ -1032,9 +1032,15 @@ ujson_reader *ujson_reader_load(const char *path)
 			goto err1;
 		}
 
+		if (res == 0)
+			break;
+
 		off += res;
 	}
 
+	ret->buf[off] = 0;
+	ret->len = off;
+
 	close(fd);
 
 	return ret;

-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-10-13 15:42 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 12:01 [LTP] [PATCH v2 00/15] Fix ujson bugs Andrea Cervesato
2026-10-13 12:01 ` [LTP] [PATCH v2 01/15] ujson: Fix 4-byte UTF-8 sequence decoding Andrea Cervesato
2026-10-13 15:42   ` [LTP] " linuxtestproject.agent
2026-10-13 12:01 ` [LTP] [PATCH v2 02/15] ujson: writer: Fix OOB read on invalid UTF-8 Andrea Cervesato
2026-10-13 12:01 ` [LTP] [PATCH v2 03/15] ujson: reader: Prevent infinite loop on EOF Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 04/15] ujson: writer: Fix open() return value check Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 05/15] ujson: reader: Return UTF-8 length when !str Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 06/15] ujson: reader: Combine UTF-16 surrogate pairs Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 07/15] ujson: reader: Check for signed integer overflow Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 08/15] ujson: writer: Return error when newline() fails Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 09/15] ujson: writer: Check return value in esc_flush() Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 10/15] ujson: reader: Parse escape sequences in object IDs Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 11/15] ujson: reader: Reject files with zero size Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 12/15] ujson: reader: Reject \u0000 escape in strings Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 13/15] ujson: writer: Set errno when a flush fails Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 14/15] ujson: writer: Advance buffer on short write Andrea Cervesato
2026-10-13 12:02 ` [LTP] [PATCH v2 15/15] ujson: writer: Flush buffer before direct writes Andrea Cervesato
  -- strict thread matches above, loose matches on Subject: below --
2026-10-05 13:25 [LTP] [PATCH 03/15] ujson: reader: Prevent infinite loop on EOF Andrea Cervesato
2026-10-05 18:06 ` [LTP] ujson: Fix 4-byte UTF-8 sequence decoding linuxtestproject.agent

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.