Repository navigation
fix(native): return empty string for negative rightstr length - #1509
sarthakdev143-lite wants to merge 1 commit into
Conversation
rightstr() computed the number of leading characters to skip as c - l.
A negative length made that larger than the string, and the cursor walk
that followed had no upper bound, so it moved past the terminating nul
until it reached an unmapped page. One statement,
`select rightstr('abcdef', -1000000000)`, therefore killed the JVM with
SIGSEGV (exit 134); no JDBC exception can catch it.
A negative length has always produced the empty string for small
magnitudes, but only because sqlite3_malloc(0) and the subsequent strcpy
happened to read an empty value. Return the empty string explicitly
before the walk. This also avoids the c - l signed overflow at INT_MIN.
Add ExtensionTest#rightstrNegativeLength covering -1000000000, -1 and a
positive-length control.
|
Thanks for the approval. The red jobs all have one cause, and it is the new test itself rather than a regression elsewhere: the PR's CI runs I reproduced both sides in a clean Linux container (JDK 25):
So CI should go green once the native libraries are rebuilt, for example with the Build Native workflow from CONTRIBUTING, which commits the updated binaries to the branch. I can't run that workflow from a fork. Until then I would not merge on the current red state. If you would rather have a test that does not take the JVM down on a stale library, I can replace the |
Summary
rightstr(text, length)in the bundledextension-functions.ccomputed the number of leading characters to skip asc - l. With a negativelengththat value is larger than the string itself, and the cursor walk that follows has no upper bound, so the pointer moves past the terminating NUL until it reaches an unmapped page:aborts the whole JVM with SIGSEGV (exit 134) inside
NativeDB.step(). No JDBC exception can catch it.A negative length has always produced the empty string for small magnitudes (e.g.
-1), but only becausesqlite3_malloc(0)and the followingstrcpyhappened to read an empty value. This returns the empty string explicitly before the walk, which also avoids thec - lsigned overflow atINT_MIN.Tests
ExtensionTest#rightstrNegativeLengthcovers-1000000000,-1, and a positive control (rightstr('abcdef', 2) = 'ef').Aborted (core dumped), exit 134).Tests run: 8, Failures: 0, Errors: 0, Skipped: 0.Verified in a clean clone with:
The
CCoverride is only for my local GCC 15, which treats the pre-existing implicitRegisterExtensionFunctionsdeclaration as an error; it is not needed by CI.Note on the committed native libraries
As with #1489, the tests run against the committed libraries under
src/main/resources/org/sqlite/native, so the test jobs will fail until Build Native regenerates them. I did not commit rebuilt binaries.Fixes #1508
Prepared with AI assistance; reviewed and tested by me.