File tree 3 files changed +21
-0
lines changed
npm-packages/convex/src/server/impl
3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ use crate::{
21
21
QuerySource ,
22
22
Search ,
23
23
SearchFilterExpression ,
24
+ MAX_QUERY_OPERATORS ,
24
25
} ,
25
26
types:: {
26
27
IndexName ,
@@ -298,6 +299,11 @@ impl TryFrom<JsonValue> for Query {
298
299
299
300
fn try_from ( value : JsonValue ) -> Result < Self > {
300
301
let json_query: JsonQuery = serde_json:: from_value ( value) ?;
302
+ anyhow:: ensure!(
303
+ json_query. operators. len( ) <= MAX_QUERY_OPERATORS ,
304
+ "Query has too many operators: {}" ,
305
+ json_query. operators. len( )
306
+ ) ;
301
307
Ok ( Query {
302
308
source : json_query. source . try_into ( ) ?,
303
309
operators : json_query
Original file line number Diff line number Diff line change @@ -1018,6 +1018,14 @@ pub enum QueryOperator {
1018
1018
Limit ( usize ) ,
1019
1019
}
1020
1020
1021
+ /// The maximum number of `QueryOperator`s allowed on a single query.
1022
+ /// This is only enforced for queries deserialized from JSON as we assume other
1023
+ /// queries come from the system.
1024
+ ///
1025
+ /// N.B.: this value is replicated in `query_impl.ts` in the `convex` npm
1026
+ /// package.
1027
+ pub const MAX_QUERY_OPERATORS : usize = 256 ;
1028
+
1021
1029
/// A query, represented as a source and a chain of operators to apply as a lazy
1022
1030
/// iteration.
1023
1031
#[ derive( Clone , Debug , PartialEq ) ]
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ import {
19
19
import { validateArg , validateArgIsNonNegativeInteger } from "./validate.js" ;
20
20
import { version } from "../../index.js" ;
21
21
22
+ const MAX_QUERY_OPERATORS = 256 ;
23
+
22
24
type QueryOperator = { filter : JSONValue } | { limit : number } ;
23
25
type Source =
24
26
| { type : "FullTableScan" ; tableName : string ; order : "asc" | "desc" | null }
@@ -223,6 +225,11 @@ export class QueryImpl implements Query<GenericTableInfo> {
223
225
) : any {
224
226
validateArg ( predicate , 1 , "filter" , "predicate" ) ;
225
227
const query = this . takeQuery ( ) ;
228
+ if ( query . operators . length >= MAX_QUERY_OPERATORS ) {
229
+ throw new Error (
230
+ `Can't construct query with more than ${ MAX_QUERY_OPERATORS } operators` ,
231
+ ) ;
232
+ }
226
233
query . operators . push ( {
227
234
filter : serializeExpression ( predicate ( filterBuilderImpl ) ) ,
228
235
} ) ;
You can’t perform that action at this time.
0 commit comments