fix: reject embedded NUL bytes in documents to prevent FTS5 corruption (#7388) - #7474
fix: reject embedded NUL bytes in documents to prevent FTS5 corruption (#7388)#7474rkfshakti wants to merge 1 commit into
Conversation
chroma-core#7388) A document string containing an embedded NUL character (U+0000) passed to upsert/add corrupts the FTS5 inverted index for the entire collection. PRAGMA quick_check reports 'malformed inverted index for FTS5 table'. NUL bytes are valid in Python strings but destructive to SQLite/FTS5. Add validation in validate_documents() to reject documents containing NUL bytes before they reach the database, with a clear error message.
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
|
Hi maintainers — gentle bump on this fix for #7388. Rejects embedded NUL bytes in documents to prevent FTS5 index corruption for the entire collection. Ready for review. Thanks! |
|
Hi maintainers — circling back on this fix for #7388. Curious if the NUL-byte rejection approach makes sense or if there's a preferred sanitization strategy. Happy to iterate. Keen to contribute! Thanks. |
|
Friendly ping — this PR has been open for a couple of days with CI passing. Would appreciate a review when time allows. |
|
Hi maintainers — following up again on this fix for #7388. Rejects embedded NUL bytes in documents to prevent FTS5 corruption. CI is green. Would appreciate a review when time allows. Thanks! |
Problem
A document string containing an embedded NUL character (U+0000) passed to
Collection.upsert()corrupts the FTS5 inverted index for the entire collection — not just that one document.PRAGMA quick_checkon the resultingchroma.sqlite3reports:NUL bytes are valid, well-formed Python strings (
"a\x00b"is legal UTF-8), so nothing in the Python-level API rejects them before they reach SQLite/FTS5.Reproduction
Fix
Add validation in
validate_documents()to reject documents containing NUL bytes before they reach the database, with a clear error message:This is a strict improvement: malformed documents get a clear error instead of silently corrupting the collection's full-text search index.
Test
Added
test_nul_byte_in_document_raises_error— verifies that:ValueErroronupsert()ValueErroronadd()Fixes #7388