rightstr(s, negative) triggers a huge allocation and returns SQLITE_NOMEM
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
Direzione di ricerca
Inizia in src/main/ext/extension-functions.c: leggi rightFunc() e confrontala con la funzione sorella leftFunc(), che restituisce già una stringa vuota per lunghezze negative. Aggiungi lo stesso limite n < 0 prima dell'aritmetica offset/dimensione e mantieni l'allocazione protetta. Fatto significa che il repro Java seleziona rightstr('abcdef', -1) senza SQLITE_NOMEM, restituendo '' o un SQLITE_ERROR regolare, coerentemente con rightstr('abcdef', 0).
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
rightstr(s, n) with a negative n does not validate the argument before computing the allocation size. The size arithmetic underflows, sqlite3_malloc() receives an enormous value, and the call fails with SQLITE_NOMEM. The same input can fatally abort the connection in other contexts. A negative length should be treated as 0 (returning an empty string) or rejected with a normal error, never turned into a huge allocation.
To Reproduce
import java.sql.*;
public class Repro {
public static void main(String[] args) throws Exception {
try (Connection c = DriverManager.getConnection("jdbc:sqlite::memory:");
Statement s = c.createStatement()) {
try (ResultSet r = s.executeQuery("SELECT rightstr('abcdef', -1)")) {
r.next();
System.out.println("=> [" + r.getObject(1) + "]");
}
}
}
}
Expected behavior
rightstr('abcdef', -1) should return an empty string (''), the same way rightstr('abcdef', 0) does, or raise a regular SQLITE_ERROR. It must not attempt an unbounded allocation and must not return SQLITE_NOMEM.
Logs
SELECT rightstr('abcdef', 0) => (empty string)
SELECT rightstr('abcdef', -1) => [SQLITE_NOMEM] A malloc() failed (out of memory)
Environment (please complete the following information):
- OS: macOS 15.6.1
- CPU architecture: arm64
- sqlite-jdbc version: 3.54.1.0
Additional context
Root cause in src/main/ext/extension-functions.c, rightFunc(): n is taken via sqlite3_value_int() and used directly when computing the result buffer size (sqlite3_malloc(ze - zt + 1)), without a n < 0 guard. With a negative n the length expression goes negative and is converted to a huge size_t, so the allocation request is absurd.
Suggested fix: clamp n to 0 when negative before computing the offset/size (or reject it explicitly), and guard the allocation with an overflow check.
Related: leftstr(s, n) handles the same input by returning '', so the two sibling functions disagree on negative lengths.
Found by PST while testing built-in functions locally.
- Lingua principale
- Java
- Stelle
- 3.3k
- Fork
- 676
- Merge medio
- 1g 15h
- PR unite (30g)
- 18
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di xerial/sqlite-jdbc
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
xerial/sqlite-jdbc#1515 ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
xerial/sqlite-jdbc#1514 ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
xerial/sqlite-jdbc#1512 ·
I maintainer di solito rispondono entro 1 giorno
-
SIGSEGV (exit 134) in bundled `rightstr()` when the length argument is a large negative numberForse già presa @sarthakdev143-lite l’ha presa 2 giorni fa. Apertahelp wanted impacts:JNI
Difficoltà 4/5 1-2 giorni Idoneità per principianti 38/100
xerial/sqlite-jdbc#1508 ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
xerial/sqlite-jdbc#1483 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di xerial/sqlite-jdbc
Issue simili
-
vips-drift
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
Stirling-Tools/JPDFium#300 ·
I maintainer di solito rispondono entro 1 giorno
-
hermes-queue
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
chrisalunlloyd2-sudo/mindpalace#403 ·
I maintainer di solito rispondono entro 1 giorno
-
Guidelines: document how to build a use case against a local, unpublished Flow/browserless-test changeForse già presa @totally-not-ai l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
vaadin/use-cases#452 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area/storage area/storage/sql
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Apicurio/apicurio-registry#11159 ·
I maintainer di solito rispondono entro 1 giorno
-
Area/Configuration Type/Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ballerina-platform/static-code-analysis-tool#217 ·
I maintainer di solito rispondono entro 1 giorno