mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.77k stars 230 forks source link

Potential unbounded recursion when checking for unsigned types #1006

Open rfk opened 3 years ago

rfk commented 3 years ago

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 commented 3 years ago

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