Skip to content

Commit 7a80808

Browse files
[4.3.x] cherrypicks (#1460)
Signed-off-by: Adrian Palacios <[email protected]> Signed-off-by: Craig Disselkoen <[email protected]> Co-authored-by: Adrian Palacios <[email protected]>
1 parent 69036a2 commit 7a80808

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

cedar-policy-core/src/evaluator.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use itertools::{Either, Itertools};
3434
use nonempty::nonempty;
3535
use smol_str::SmolStr;
3636

37-
#[cfg(not(target_arch = "wasm32"))]
3837
const REQUIRED_STACK_SPACE: usize = 1024 * 100;
3938

4039
// PANIC SAFETY `Name`s in here are valid `Name`s
@@ -1108,11 +1107,9 @@ impl Value {
11081107

11091108
#[inline(always)]
11101109
fn stack_size_check() -> Result<()> {
1111-
#[cfg(not(target_arch = "wasm32"))]
1112-
{
1113-
if stacker::remaining_stack().unwrap_or(0) < REQUIRED_STACK_SPACE {
1114-
return Err(EvaluationError::recursion_limit(None));
1115-
}
1110+
// We assume there's enough space if we cannot determine it with `remaining_stack`
1111+
if stacker::remaining_stack().unwrap_or(REQUIRED_STACK_SPACE) < REQUIRED_STACK_SPACE {
1112+
return Err(EvaluationError::recursion_limit(None));
11161113
}
11171114
Ok(())
11181115
}

cedar-policy-core/src/evaluator/err.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ impl EvaluationError {
321321
}
322322

323323
/// Construct a [`RecursionLimit`] error
324-
#[cfg(not(target_arch = "wasm32"))]
325324
pub(crate) fn recursion_limit(source_loc: Option<Loc>) -> Self {
326325
evaluation_errors::RecursionLimitError { source_loc }.into()
327326
}

cedar-policy-validator/src/typecheck.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ use cedar_policy_core::{
4747
expr_builder::ExprBuilder as _,
4848
};
4949

50-
#[cfg(not(target_arch = "wasm32"))]
5150
const REQUIRED_STACK_SPACE: usize = 1024 * 100;
5251

5352
/// Basic result for typechecking
@@ -352,8 +351,8 @@ impl<'a> SingleEnvTypechecker<'a> {
352351
e: &'b Expr,
353352
type_errors: &mut Vec<ValidationError>,
354353
) -> TypecheckAnswer<'b> {
355-
#[cfg(not(target_arch = "wasm32"))]
356-
if stacker::remaining_stack().unwrap_or(0) < REQUIRED_STACK_SPACE {
354+
// We assume there's enough space if we cannot determine it with `remaining_stack`
355+
if stacker::remaining_stack().unwrap_or(REQUIRED_STACK_SPACE) < REQUIRED_STACK_SPACE {
357356
return TypecheckAnswer::RecursionLimit;
358357
}
359358

cedar-policy/src/api.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ impl Authorizer {
873873
/// The authorizer uses the `stacker` crate to manage stack size and tries to use a sane default.
874874
/// If the default is not right for you, you can try wrapping the authorizer or individual calls
875875
/// to `is_authorized` in `stacker::grow`.
876+
/// Note that on platforms not supported by `stacker` (e.g., Wasm, Android),
877+
/// the authorizer will simply assume that the stack size is sufficient. As a result, large inputs
878+
/// may result in stack overflows and crashing the process.
879+
/// But on all platforms supported by `stacker` (Linux, macOS, ...), Cedar will return the
880+
/// graceful error `RecursionLimit` instead of crashing.
876881
/// ```
877882
/// # use cedar_policy::{Authorizer, Context, Entities, EntityId, EntityTypeName,
878883
/// # EntityUid, Request,PolicySet};

0 commit comments

Comments
 (0)