[BUG] Incorrect use of %d -> db corruption or crash?
Posted: Wed Dec 05, 2012 6:29 pm
I noticed several reports of SQLite database corruption, so I thought I’d have a quick browse through the source (as I’m quite familiar with SQLite).
The incorrect use of the ‘%d’ format specifier in SQL statements (via calls to SQLDatabase-performQueryWithFormat: & Database-executeSQLWithFormat:) could lead to possible db corruption or crashes.
The ‘%d’ format specifier is specified to accept a 32-bit integer.
In multiple locations an NSInteger is being passed.
On x86-64 (& PPC-64) an NSInteger is typedef’ed as ‘long’ — which is a 64-bit integer. [On i386 & PPC NSInteger is 32-bit.]
At the very least this will result in the wrong values being passed to SQL statements & SQLite.
The formatters should be replaced with ‘%ld’ as this is 32-bit on i386 & PPC & 64-bit on x86-64 & PPC-64.
Also, I noticed several occurrences of the ‘%i’ format specifier. While this is probably equivalent to ‘%d’ it is not actually defined for NSString-initWithFormat:arguments: which is the ultimate consumer of the format strings.
See <https://developer.apple.com/library/mac ... fiers.html>.
Regards,
Chris
The incorrect use of the ‘%d’ format specifier in SQL statements (via calls to SQLDatabase-performQueryWithFormat: & Database-executeSQLWithFormat:) could lead to possible db corruption or crashes.
The ‘%d’ format specifier is specified to accept a 32-bit integer.
In multiple locations an NSInteger is being passed.
On x86-64 (& PPC-64) an NSInteger is typedef’ed as ‘long’ — which is a 64-bit integer. [On i386 & PPC NSInteger is 32-bit.]
At the very least this will result in the wrong values being passed to SQL statements & SQLite.
The formatters should be replaced with ‘%ld’ as this is 32-bit on i386 & PPC & 64-bit on x86-64 & PPC-64.
Also, I noticed several occurrences of the ‘%i’ format specifier. While this is probably equivalent to ‘%d’ it is not actually defined for NSString-initWithFormat:arguments: which is the ultimate consumer of the format strings.
See <https://developer.apple.com/library/mac ... fiers.html>.
Regards,
Chris