uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Potential unbounded recursion when checking for unsigned types

Open rfk opened this issue 4 years ago • 1 comments

Consider the following test:

    fn test_no_infinite_recursion_when_walking_types() {
        const UDL: &str = r#"
            namespace test{};
            interface Testing {
                void tester(Testing foo);
            };
        "#;
        let ci = ComponentInterface::from_webidl(UDL).unwrap();
        assert!(! ci.type_contains_unsigned_types(&Type::Object("Testing".into())));
    }

This intereface doesn't contain any unsigned types, so the test should pass. When I run it on latest main I get:

thread 'interface::test::test_no_infinite_recursion_when_walking_types' has overflowed its stack
fatal runtime error: stack overflow

The trouble here is that Type::Object("Testing") contains a reference to itself via one of the method arguments, so when we try to walk all the contained types and look for unsigned types, we end up doing unbounded recursion.

┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-77

rfk avatar Aug 06 '21 02:08 rfk

The refactor in https://github.com/mozilla/uniffi-rs/pull/1005 adds tests for, and a fix for, this unbounded recursion issue.

rfk avatar Aug 06 '21 06:08 rfk