sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | /* |
| 2 | ** 2007 May 7 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** |
| 13 | ** This file defines various limits of what SQLite can process. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | ** The maximum length of a TEXT or BLOB in bytes. This also |
| 18 | ** limits the size of a row in a table or index. |
| 19 | ** |
| 20 | ** The hard limit is the ability of a 32-bit signed integer |
| 21 | ** to count the size: 2^31-1 or 2147483647. |
| 22 | */ |
| 23 | #ifndef SQLITE_MAX_LENGTH |
| 24 | # define SQLITE_MAX_LENGTH 1000000000 |
| 25 | #endif |
| 26 | #define SQLITE_MIN_LENGTH 30 /* Minimum value for the length limit */ |
| 27 | |
| 28 | /* |
| 29 | ** Maximum size of any single memory allocation. |
| 30 | ** |
| 31 | ** This is not a limit on the total amount of memory used. This is |
| 32 | ** a limit on the size parameter to sqlite3_malloc() and sqlite3_realloc(). |
| 33 | ** |
| 34 | ** The upper bound is slightly less than 2GiB: 0x7ffffeff == 2,147,483,391 |
| 35 | ** This provides a 256-byte safety margin for defense against 32-bit |
| 36 | ** signed integer overflow bugs when computing memory allocation sizes. |
| 37 | ** Paranoid applications might want to reduce the maximum allocation size |
| 38 | ** further for an even larger safety margin. 0x3fffffff or 0x0fffffff |
| 39 | ** or even smaller would be reasonable upper bounds on the size of a memory |
| 40 | ** allocations for most applications. |
| 41 | */ |
| 42 | #ifndef SQLITE_MAX_ALLOCATION_SIZE |
| 43 | # define SQLITE_MAX_ALLOCATION_SIZE 2147483391 |
| 44 | #endif |
| 45 | #if SQLITE_MAX_ALLOCATION_SIZE>2147483391 |
| 46 | # error Maximum size for SQLITE_MAX_ALLOCATION_SIZE is 2147483391 |
| 47 | #endif |
| 48 | |
| 49 | /* |
| 50 | ** This is the maximum number of |
| 51 | ** |
| 52 | ** * Columns in a table |
| 53 | ** * Columns in an index |
| 54 | ** * Columns in a view |
| 55 | ** * Terms in the SET clause of an UPDATE statement |
| 56 | ** * Terms in the result set of a SELECT statement |
| 57 | ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. |
| 58 | ** * Terms in the VALUES clause of an INSERT statement |
| 59 | ** |
| 60 | ** The hard upper limit here is 32767. Most database people will |
| 61 | ** tell you that in a well-normalized database, you usually should |
| 62 | ** not have more than a dozen or so columns in any table. And if |
| 63 | ** that is the case, there is no point in having more than a few |
| 64 | ** dozen values in any of the other situations described above. |
| 65 | ** |
| 66 | ** An index can only have SQLITE_MAX_COLUMN columns from the user |
| 67 | ** point of view, but the underlying b-tree that implements the index |
| 68 | ** might have up to twice as many columns in a WITHOUT ROWID table, |
| 69 | ** since must also store the primary key at the end. Hence the |
| 70 | ** column count for Index is u16 instead of i16. |
| 71 | */ |
| 72 | #if !defined(SQLITE_MAX_COLUMN) |
| 73 | # define SQLITE_MAX_COLUMN 2000 |
| 74 | #elif SQLITE_MAX_COLUMN>32767 |
| 75 | # error SQLITE_MAX_COLUMN may not exceed 32767 |
| 76 | #endif |
| 77 | |
| 78 | /* |
| 79 | ** The maximum length of a single SQL statement in bytes. |
| 80 | ** |
| 81 | ** It used to be the case that setting this value to zero would |
| 82 | ** turn the limit off. That is no longer true. It is not possible |
| 83 | ** to turn this limit off. |
| 84 | ** |
| 85 | ** The hard limit is the largest possible 32-bit signed integer less |
| 86 | ** 1024, or 2147482624. |
| 87 | */ |
| 88 | #ifndef SQLITE_MAX_SQL_LENGTH |
| 89 | # define SQLITE_MAX_SQL_LENGTH 1000000000 |
| 90 | #endif |
| 91 | |
| 92 | /* |
| 93 | ** The maximum depth of an expression tree. The expression tree depth |
| 94 | ** is also limited indirectly by SQLITE_MAX_SQL_LENGTH and by |
| 95 | ** SQLITE_MAX_PARSER_DEPTH. Reducing the maximum complexity of |
| 96 | ** expressions can help prevent excess memory usage by hostile SQL. |
| 97 | ** |
| 98 | ** A value of 0 for this compile-time option causes all expression |
| 99 | ** depth limiting code to be omitted. |
| 100 | */ |
| 101 | #ifndef SQLITE_MAX_EXPR_DEPTH |
| 102 | # define SQLITE_MAX_EXPR_DEPTH 1000 |
| 103 | #endif |
| 104 | |
| 105 | /* |
| 106 | ** The maximum depth of the LALR(1) stack used in the parser that |
| 107 | ** interprets SQL inputs. The parser stack depth can also be limited |
| 108 | ** indirectly by SQLITE_MAX_SQL_LENGTH. Limiting the parser stack |
| 109 | ** depth can help prevent excess memory usage and excess CPU stack |
| 110 | ** usage when processing hostile SQL. |
| 111 | ** |
| 112 | ** Prior to version 3.45.0 (2024-01-15), the parser stack was |
| 113 | ** hard-coded to 100 entries, and that worked fine for almost all |
| 114 | ** applications. So the upper bound on this limit need not be large. |
| 115 | */ |
| 116 | #ifndef SQLITE_MAX_PARSER_DEPTH |
| 117 | # define SQLITE_MAX_PARSER_DEPTH 2500 |
| 118 | #endif |
| 119 | |
| 120 | /* |
| 121 | ** The maximum number of terms in a compound SELECT statement. |
| 122 | ** The code generator for compound SELECT statements does one |
| 123 | ** level of recursion for each term. A stack overflow can result |
| 124 | ** if the number of terms is too large. In practice, most SQL |
| 125 | ** never has more than 3 or 4 terms. Use a value of 0 to disable |
| 126 | ** any limit on the number of terms in a compound SELECT. |
| 127 | */ |
| 128 | #ifndef SQLITE_MAX_COMPOUND_SELECT |
| 129 | # define SQLITE_MAX_COMPOUND_SELECT 500 |
| 130 | #endif |
| 131 | |
| 132 | /* |
| 133 | ** The maximum number of opcodes in a VDBE program. |
| 134 | ** Not currently enforced. |
| 135 | */ |
| 136 | #ifndef SQLITE_MAX_VDBE_OP |
| 137 | # define SQLITE_MAX_VDBE_OP 250000000 |
| 138 | #endif |
| 139 | |
| 140 | /* |
| 141 | ** The maximum number of arguments to an SQL function. |
| 142 | ** |
| 143 | ** This value has a hard upper limit of 32767 due to storage |
| 144 | ** constraints (it needs to fit inside a i16). We keep it |
| 145 | ** lower than that to prevent abuse. |
| 146 | */ |
| 147 | #ifndef SQLITE_MAX_FUNCTION_ARG |
| 148 | # define SQLITE_MAX_FUNCTION_ARG 1000 |
| 149 | #endif |
| 150 | |
| 151 | /* |
| 152 | ** The suggested maximum number of in-memory pages to use for |
| 153 | ** the main database table and for temporary tables. |
| 154 | ** |
| 155 | ** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000, |
| 156 | ** which means the cache size is limited to 2048000 bytes of memory. |
| 157 | ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be |
| 158 | ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options. |
| 159 | */ |
| 160 | #ifndef SQLITE_DEFAULT_CACHE_SIZE |
| 161 | # define SQLITE_DEFAULT_CACHE_SIZE -2000 |
| 162 | #endif |
| 163 | |
| 164 | /* |
| 165 | ** The default number of frames to accumulate in the log file before |
| 166 | ** checkpointing the database in WAL mode. |
| 167 | */ |
| 168 | #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
| 169 | # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 |
| 170 | #endif |
| 171 | |
| 172 | /* |
| 173 | ** The maximum number of attached databases. This must be between 0 |
| 174 | ** and 125. The upper bound of 125 is because the attached databases are |
| 175 | ** counted using a signed 8-bit integer which has a maximum value of 127 |
| 176 | ** and we have to allow 2 extra counts for the "main" and "temp" databases. |
| 177 | */ |
| 178 | #ifndef SQLITE_MAX_ATTACHED |
| 179 | # define SQLITE_MAX_ATTACHED 10 |
| 180 | #endif |
| 181 | |
| 182 | |
| 183 | /* |
| 184 | ** The maximum value of a ?nnn wildcard that the parser will accept. |
| 185 | ** If the value exceeds 32767 then extra space is required for the Expr |
| 186 | ** structure. But otherwise, we believe that the number can be as large |
| 187 | ** as a signed 32-bit integer can hold. |
| 188 | */ |
| 189 | #ifndef SQLITE_MAX_VARIABLE_NUMBER |
| 190 | # define SQLITE_MAX_VARIABLE_NUMBER 32766 |
| 191 | #endif |
| 192 | |
| 193 | /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 194 | ** imposed by the use of 16-bit offsets within each page. |
| 195 | ** |
| 196 | ** Earlier versions of SQLite allowed the user to change this value at |
| 197 | ** compile time. This is no longer permitted, on the grounds that it creates |
| 198 | ** a library that is technically incompatible with an SQLite library |
| 199 | ** compiled with a different limit. If a process operating on a database |
| 200 | ** with a page-size of 65536 bytes crashes, then an instance of SQLite |
| 201 | ** compiled with the default page-size limit will not be able to rollback |
| 202 | ** the aborted transaction. This could lead to database corruption. |
| 203 | */ |
| 204 | #ifdef SQLITE_MAX_PAGE_SIZE |
| 205 | # undef SQLITE_MAX_PAGE_SIZE |
| 206 | #endif |
| 207 | #define SQLITE_MAX_PAGE_SIZE 65536 |
| 208 | |
| 209 | |
| 210 | /* |
| 211 | ** The default size of a database page. |
| 212 | */ |
| 213 | #ifndef SQLITE_DEFAULT_PAGE_SIZE |
| 214 | # define SQLITE_DEFAULT_PAGE_SIZE 4096 |
| 215 | #endif |
| 216 | #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 217 | # undef SQLITE_DEFAULT_PAGE_SIZE |
| 218 | # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 219 | #endif |
| 220 | |
| 221 | /* |
| 222 | ** Ordinarily, if no value is explicitly provided, SQLite creates databases |
| 223 | ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain |
| 224 | ** device characteristics (sector-size and atomic write() support), |
| 225 | ** SQLite may choose a larger value. This constant is the maximum value |
| 226 | ** SQLite will choose on its own. |
| 227 | */ |
| 228 | #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 229 | # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 |
| 230 | #endif |
| 231 | #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 232 | # undef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 233 | # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 234 | #endif |
| 235 | #if SQLITE_MAX_DEFAULT_PAGE_SIZE<SQLITE_DEFAULT_PAGE_SIZE |
| 236 | # undef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 237 | # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_DEFAULT_PAGE_SIZE |
| 238 | #endif |
| 239 | |
| 240 | |
| 241 | /* |
| 242 | ** Maximum number of pages in one database file. |
| 243 | ** |
| 244 | ** This is really just the default value for the max_page_count pragma. |
| 245 | ** This value can be lowered (or raised) at run-time using the |
| 246 | ** max_page_count macro. |
| 247 | */ |
| 248 | #ifndef SQLITE_MAX_PAGE_COUNT |
| 249 | # define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */ |
| 250 | #endif |
| 251 | |
| 252 | /* |
| 253 | ** Maximum length (in bytes) of the pattern in a LIKE or GLOB |
| 254 | ** operator. |
| 255 | */ |
| 256 | #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| 257 | # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 |
| 258 | #endif |
| 259 | |
| 260 | /* |
| 261 | ** Maximum depth of recursion for triggers. |
| 262 | ** |
| 263 | ** A value of 1 means that a trigger program will not be able to itself |
| 264 | ** fire any triggers. A value of 0 means that no trigger programs at all |
| 265 | ** may be executed. |
| 266 | */ |
| 267 | #ifndef SQLITE_MAX_TRIGGER_DEPTH |
| 268 | # define SQLITE_MAX_TRIGGER_DEPTH 1000 |
| 269 | #endif |
| 270 | |
| 271 | /* |
| 272 | ** Maximum number of objects defined by a single database schema. |
| 273 | ** Objects include: |
| 274 | ** |
| 275 | ** * tables (including the sqlite_schema table) |
| 276 | ** * virtual tables |
| 277 | ** * named indexes |
| 278 | ** * indexes created automatically by UNIQUE and PRIMARY KEY constraints |
| 279 | ** * triggers |
| 280 | ** * views |
| 281 | ** |
| 282 | ** The total of all of the above is the number of objects in the schema, |
| 283 | ** and that number may not exceed this value. |
| 284 | ** |
| 285 | ** The maximum number of objects is restricted to forestall theoretical |
| 286 | ** signed integer overflow attacks using databases with billions of |
| 287 | ** schema objects. Such attacks are "theoretical" because memory and |
| 288 | ** disk space constraints would be reached long before billions of schema |
| 289 | ** objects could be created. Even so, it seems good to have a well defined |
| 290 | ** upper limit on the complexity of the schema, for defense in depth. |
| 291 | ** No real-world application should ever get anywhere close to hitting |
| 292 | ** this limit. |
| 293 | */ |
| 294 | #ifndef SQLITE_MAX_SCHEMA |
| 295 | # define SQLITE_MAX_SCHEMA 10000000 |
| 296 | #endif |
| 297 | |
| 298 | /* |
| 299 | ** Maximum number of SQL statements allowed in the body of a single |
| 300 | ** trigger. |
| 301 | */ |
| 302 | #ifndef SQLITE_MAX_TRIGGER_STEPS |
| 303 | # define SQLITE_MAX_TRIGGER_STEPS 65000 |
| 304 | #endif |
| 305 | |
| 306 | /* |
| 307 | ** Maximum number of CTE cursors (approximately). This limit will be |
| 308 | ** exceeded if any CTE uses a cursor number larger than this value, even |
| 309 | ** of some of the cursors are used for something other than CTEs. |
| 310 | ** |
| 311 | ** The purpose of this limit is to prevent resource exhaustion caused |
| 312 | ** by hostile SQL inputs such as: |
| 313 | ** |
| 314 | ** WITH c0 AS (SELECT 1 AS x), |
| 315 | ** c1 AS (SELECT a.x AS x FROM c0 a, c0 b), |
| 316 | ** c2 AS (SELECT a.x AS x FROM c1 a, c1 b), |
| 317 | ** ... |
| 318 | ** c17 AS (SELECT a.x AS x FROM c16 a, c16 b) |
| 319 | ** SELECT count(*) FROM c17; |
| 320 | ** |
| 321 | ** See Bug 2026-10-04T05:35:14Z |
| 322 | */ |
| 323 | #ifndef SQLITE_MAX_CTES |
| 324 | # define SQLITE_MAX_CTES 50000 |
| 325 | #endif |