SQLite

View Ticket
Login
Ticket Hash: 57c971fc74524aa46e0b367dbed9a9a77aed4ebc
Title: Some user defined string functions do not operate correctly on strings with embedded nuls
Status: Closed Type: Code_Defect
Severity: Minor Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2011-10-31 18:44:32
Version Found In: 3.7.8
Description:
SQLite supports embedded NUL in strings, both via the C API and SQL. For example this will create one:
INSERT INTO table VALUES('abc' || x'00' || 'def');

Many of the user defined string functions such as quote, upper/lower, length, replace, (r)trim stop their operations at the first NUL rather than at the end of the string.

Somewhat related you can also create UTF16 sequences with odd numbers of bytes using the insert sequence above because || operates on bytes not characters.

This topic was discussed on the mailing list:

http://thread.gmane.org/gmane.comp.db.sqlite.general/68307/focus=68400

drh added on 2011-10-13 18:01:28:
Updated documentation to try to make it clearer that the result of expressions involving strings with embedded NUL characters is undefined. Also added more detail to the documentation on sqlite3_prepare(), sqlite3_bind_text(), and sqlite3_result_text() to try to clear up confusion about the use of NUL terminators.