Skip to content

Calls to cedar_policy::Entity::new fails in android bindings generated using uniffi if the entity's attributes are not empty. #1443

@rmarinn

Description

@rmarinn

Before opening, please confirm:

Bug Category

Other

Describe the bug

Calls to cedar_policy::Entity::new fails in android bindings generated using uniffi if the entity's attributes are not empty.

It works fine if the entity does not have attributes.

Expected behavior

I expected the entity to be created successfully when it gets called in the Kotlin code.

Reproduction steps

  1. Write rust code that creates an entity using cedar_policy::Entity::new.
  2. Create android bindings using uniffi.
  3. Run the code in an android device or emulator.

Code Snippet

let test_entity = "Test::\"abc\"".parse().expect("parse resource uid");
let test_entity_attrs = HashMap::from([
    (
        "item1".to_string(),
        RestrictedExpression::new_string("abc".to_string()),
    ),
    ("attr2".to_string(), RestrictedExpression::new_long(123)),
]);

// This call to Entity::new is what fails in the android binding
let test_entity = Entity::new(test_entity, test_entity_attrs, HashSet::new()).expect("build entity");

Log output

FATAL EXCEPTION: main
Process: com.example.exampleapp, PID: 15076
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:590)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
Caused by: java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886) 
Caused by: uniffi.android_bindings.InternalException: build entity: EntityAttrEvaluationError { uid: EntityUid(EntityUID { ty: EntityType(Name(InternalName { id: Id("Test"), path: [], loc: Some(Loc { span: SourceSpan { offset: SourceOffset(0), length: 4 }, src: "Test::\"abc\"" }) })), eid: Eid("abc"), loc: Some(Loc { span: SourceSpan { offset: SourceOffset(0), length: 11 }, src: "Test::\"abc\"" }) }), attr_or_tag: "item1", was_attr: true, err: RecursionLimit(RecursionLimitError { source_loc: None }) }

Additional configuration

No response

Operating System

Android

Additional information and screenshots

I think the issue is caused by cedar_policy trying to use stacker::remaining_stack in cedar-policy-core/src/evaludator.rs around line 945 inside the stack_size_check function. The stacker::remaining_stackfunction will always returnNone` when called in an adroid device or emulator.

I also made this repository for convenience when trying to reproduce the issue: https://github.com/rmarinn/cedar-android-bindings-bug.

We also tried it in Swift (also used uniffi to create the bindings) and the same issue arises.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working. This is as high priority issue.internal-improvementRefactoring, minor performance improvement, or other changes that Cedar users may never notice

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions