mirror of
https://github.com/sqlite/sqlite.git
synced 2026-10-28 09:46:20 +08:00
Prevent scalar subqueries from ever returning a value with a non-zero subtype.
Report [bugs:/info/2026-10-12T13:52:22Z | 2026-10-12T13:52:22Z]. Re-added after the addition of a necessary prerequisite in the previous check-in. FossilOrigin-Name: 8ab55e0185a1956fb3e131bc5faae0cf3ff5abb1f553217f2d63fcb15c75cc1f
This commit is contained in:
1 parent
7815214b6c
commit
394e7bc1ac
4 files changed
+221
-9
No files matched your search
@@ -1,5 +1,5 @@
|
||||
C An\sunknown\sfunction\scan\sbe\sseen\sin\sexprNodeCanReturnSubtype(),\sbut\sonly\nif\sSQLite\sis\scompiled\swith\sSQLITE_ENABLE_UNKNOWN_SQL_FUNCTIONS.\s\sAdjust\nasserts\saccordingly.
|
||||
D 2026-10-12T21:24:29.331
|
||||
C Prevent\sscalar\ssubqueries\sfrom\sever\sreturning\sa\svalue\swith\sa\snon-zero\ssubtype.\nReport\s[bugs:/info/2026-10-12T13:52:22Z\s|\s2026-10-12T13:52:22Z].\s\sRe-added\nafter\sthe\saddition\sof\sa\snecessary\sprerequisite\sin\sthe\sprevious\scheck-in.
|
||||
D 2026-10-12T21:33:49.503
|
||||
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
@@ -752,7 +752,7 @@ F src/date.c 080641f59097d14fc7341f8bc0458d273b3a62d8381916db8ccbc89c2aae07b3
|
||||
F src/dbpage.c ec8590c5e7a564cef28ca3c6156521316a4d26cb572a34841b0bcb26b67b3f97
|
||||
F src/dbstat.c 34d4e825fbf763640ce3dbc56910ab080495ef4a6efb48b2b1852a43d43763fc
|
||||
F src/delete.c 59eeca3fb88c29329afc41bb803ee568b120d9dd7470b5f38ab55cc38390b451
|
||||
F src/expr.c b02c1ae0014ba03a6384c2666c80fa561df46ab5f73f83a6e79cd82f65c7e73e
|
||||
F src/expr.c 5b3f74fb8c7b69e4ee34cb7cb326a95a2e0a0d600bff1e7a7ff9038db3ad88ef
|
||||
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
|
||||
F src/fkey.c 26788ae6c785d70f9829c4176e9764447014fc73e6ba31e9f1881720a64ae7f1
|
||||
F src/func.c 54d96eeafcb6ec4cff92028ea0f7bb09e27b375b248d969aeb80a61e560ef302
|
||||
@@ -1773,6 +1773,7 @@ F test/subquery2.test ab96ff3fa9c4e3dce0d699f74e61c50250ed4335bc8f400e127707d552
|
||||
F test/subselect.test 0966aa8e720224dbd6a5e769a3ec2a723e332303
|
||||
F test/substr.test 6a3d2c32b4d58ab063041ce67ecb16427ca5d3cd06d8d17c7b4775cbaa86fc88
|
||||
F test/subtype1.test 6e385ea8c0cab8d51f8193a8b107669224486fba0601ee256ad66a57cb4b77bc
|
||||
F test/subtype2.test a2da5636a66b752f3fa0346ce43c06098952853c5bdd050b37adf9dc44afc7c9
|
||||
F test/superlock.test 85256830339a6871ce36a2ef591c3f67716a701b5497788fb2068b90159c2442
|
||||
F test/swarmvtab.test 250231404fcac88f61a6c147bb0e3a118ed879278cd3ccb0ae2d3a729e1e8e26
|
||||
F test/swarmvtab2.test c948cb2fdfc5b01d85e8f6d6504854202dc1a0782ab2a0ed61538f27cbd0aa5c
|
||||
@@ -2285,8 +2286,9 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
|
||||
F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
|
||||
P 7b827c44ab843248b66de6fb753aad83af153085d501462b138954ceca7fee81
|
||||
R ade8985437b50a2e56e14a3954f8e317
|
||||
P dcf20611cdd4a250531d0e753144ab1b6796635331bb906df0e174aea4bd4158
|
||||
Q +af3c900e2b5251bcbc0611dbe2f86b13fd2daa07bcf42563a9d6db46dfdd6b3d
|
||||
R 972c3b48ede8c133fc8a4f75f75cbe9d
|
||||
U drh
|
||||
Z 4a20ae8ecf4e3ae1d676ccb681a9f0bb
|
||||
Z a17300c5e8b54d6da0597a60d2790a1a
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
+1
-1
@@ -1 +1 @@
|
||||
dcf20611cdd4a250531d0e753144ab1b6796635331bb906df0e174aea4bd4158
|
||||
8ab55e0185a1956fb3e131bc5faae0cf3ff5abb1f553217f2d63fcb15c75cc1f
|
||||
+8
-2
@@ -4038,6 +4038,12 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
}
|
||||
sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
|
||||
|
||||
if( dest.eDest==SRT_Mem
|
||||
&& sqlite3ExprCanReturnSubtype(pParse, pSel->pEList->a[0].pExpr)
|
||||
){
|
||||
sqlite3VdbeAddOp1(v, OP_ClrSubtype, rReg);
|
||||
}
|
||||
|
||||
/* Subroutine return */
|
||||
assert( ExprUseYSub(pExpr) );
|
||||
assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
|
||||
@@ -4793,7 +4799,7 @@ static int exprCodeInlineFunction(
|
||||
**
|
||||
** The only expressions that can return a subtype are:
|
||||
**
|
||||
** 1. A function
|
||||
** 1. A function, including an aggregate function
|
||||
** 2. The no-op "+" operator
|
||||
** 3. A CASE...END expression
|
||||
** 4. A CAST() expression
|
||||
@@ -4818,7 +4824,7 @@ static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){
|
||||
){
|
||||
return WRC_Continue;
|
||||
}
|
||||
if( pExpr->op!=TK_FUNCTION ){
|
||||
if( pExpr->op!=TK_FUNCTION && pExpr->op!=TK_AGG_FUNCTION ){
|
||||
return WRC_Prune;
|
||||
}
|
||||
assert( ExprUseXList(pExpr) );
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
# 2026 October 12
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. Specifically,
|
||||
# it tests that scalar sub-queries never return values with subtypes.
|
||||
#
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix subtype2
|
||||
|
||||
do_execsql_test 1.0.1 {
|
||||
SELECT
|
||||
json_group_object(
|
||||
'key',
|
||||
(SELECT CAST(json(0) AS TEXT)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE k = 1
|
||||
ORDER BY k)
|
||||
) AS q1,
|
||||
json_group_object(
|
||||
'key',
|
||||
(SELECT CAST(json(0) AS TEXT)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE NOT (NOT (k = 1))
|
||||
ORDER BY k)
|
||||
) AS q2;
|
||||
} {
|
||||
{{"key":"0"}} {{"key":"0"}}
|
||||
}
|
||||
|
||||
do_execsql_test 1.0.2 {
|
||||
SELECT
|
||||
json_group_object(
|
||||
'key',
|
||||
(SELECT json(0)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE k = 1
|
||||
ORDER BY k)
|
||||
) AS q1,
|
||||
json_group_object(
|
||||
'key',
|
||||
(SELECT json(0)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE NOT (NOT (k = 1))
|
||||
ORDER BY k)
|
||||
) AS q2;
|
||||
} {
|
||||
{{"key":"0"}} {{"key":"0"}}
|
||||
}
|
||||
|
||||
do_execsql_test 1.0.3 {
|
||||
SELECT json_group_object(
|
||||
'key',
|
||||
(SELECT json(0)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE k = 1
|
||||
ORDER BY k)
|
||||
);
|
||||
} {
|
||||
{{"key":"0"}}
|
||||
}
|
||||
|
||||
do_execsql_test 1.0.4 {
|
||||
SELECT json_group_object(
|
||||
'key',
|
||||
(SELECT json(0)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE (NOT (NOT (k = 1)))
|
||||
ORDER BY k)
|
||||
);
|
||||
} {
|
||||
{{"key":"0"}}
|
||||
}
|
||||
|
||||
do_execsql_test 1.0.5 {
|
||||
SELECT subtype (
|
||||
(SELECT json(0)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE k = 1
|
||||
ORDER BY k)
|
||||
);
|
||||
} {0}
|
||||
|
||||
do_execsql_test 1.0.6 {
|
||||
SELECT subtype (
|
||||
(SELECT json(0)
|
||||
FROM (SELECT 1 AS k)
|
||||
WHERE (NOT (NOT (k = 1)))
|
||||
ORDER BY k)
|
||||
);
|
||||
} {0}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
SELECT json_group_object( 'key', (SELECT CAST(json(0) AS TEXT)) );
|
||||
} {{{"key":"0"}}}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
SELECT 'key', typeof( (SELECT CAST(json(0) AS TEXT)) )
|
||||
} {key text}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
SELECT 'key', subtype( (SELECT CAST(json(0) AS TEXT)) )
|
||||
} {key 0}
|
||||
|
||||
do_execsql_test 2.4.1 {
|
||||
SELECT 'key', subtype( json(0) )
|
||||
} {key 74}
|
||||
do_execsql_test 2.4.2 {
|
||||
SELECT 'key', subtype( (SELECT json(0)) )
|
||||
} {key 0}
|
||||
|
||||
do_execsql_test 2.5 {
|
||||
SELECT 'key', subtype( max(0) )
|
||||
} {key 0}
|
||||
|
||||
do_execsql_test 2.6 {
|
||||
SELECT 'key', typeof( json(0) )
|
||||
} {key text}
|
||||
|
||||
do_execsql_test 2.7 {
|
||||
SELECT 'key', subtype( +json(0) )
|
||||
} {key 74}
|
||||
|
||||
do_execsql_test 2.8 {
|
||||
SELECT 'key', coalesce(NULL, json(0))
|
||||
} {key 0}
|
||||
|
||||
do_execsql_test 2.9 {
|
||||
SELECT 'key', coalesce(json(0), NULL)
|
||||
} {key 0}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
reset_db
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
INSERT INTO t1 values('a', 1);
|
||||
INSERT INTO t1 values('b', 2);
|
||||
INSERT INTO t1 values('c', 3);
|
||||
}
|
||||
|
||||
do_execsql_test 3.1 {
|
||||
SELECT max(
|
||||
(SELECT json( b ) FROM t1 WHERE t1.b=o.b)
|
||||
) FROM t1 AS o;
|
||||
} {3}
|
||||
|
||||
do_execsql_test 3.2 {
|
||||
SELECT subtype ((
|
||||
SELECT max(
|
||||
(SELECT json( b ) FROM t1 WHERE t1.b=o.b)
|
||||
) FROM t1 AS o
|
||||
))
|
||||
} {0}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Test that aggregate scalar sub-queries do not return subtypes as well.
|
||||
#
|
||||
reset_db
|
||||
|
||||
do_execsql_test 4.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
INSERT INTO t1 VALUES(1, '[1]');
|
||||
INSERT INTO t1 VALUES(2, '[2]');
|
||||
}
|
||||
|
||||
do_execsql_test 4.1.1 {
|
||||
SELECT subtype( json_group_array(a) ) FROM t1;
|
||||
} {74}
|
||||
do_execsql_test 4.1.2 {
|
||||
SELECT subtype( (SELECT json_group_array(a) FROM t1) );
|
||||
} {0}
|
||||
do_execsql_test 4.1.3 {
|
||||
SELECT json_array( (SELECT json_group_array(a) FROM t1) );
|
||||
} {{["[1,2]"]}}
|
||||
|
||||
do_execsql_test 4.2.1 {
|
||||
SELECT subtype( (SELECT json_group_object('k', a) FROM t1) );
|
||||
} {0}
|
||||
do_execsql_test 4.2.2 {
|
||||
SELECT json_array( (SELECT json_group_object('k', a) FROM t1) );
|
||||
} {{["{\"k\":1,\"k\":2}"]}}
|
||||
|
||||
do_execsql_test 4.3.1 {
|
||||
SELECT subtype( max(json(b)) ) FROM t1;
|
||||
} {74}
|
||||
do_execsql_test 4.3.2 {
|
||||
SELECT subtype( (SELECT max(json(b)) FROM t1) );
|
||||
} {0}
|
||||
do_execsql_test 4.3.3 {
|
||||
SELECT json_array( (SELECT min(json(b)) FROM t1) );
|
||||
} {{["[1]"]}}
|
||||
|
||||
finish_test
|
||||
|
||||
Reference in new issue
Block a user