Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in MaterialXCore::Element::setChildIndex() due to off-by-one error in index check #1581

Closed
StefanHabel opened this issue Oct 22, 2023 · 3 comments

Comments

@StefanHabel
Copy link
Contributor

I believe I found an off-by-one crash bug in MaterialXCore::Element::setChildIndex().

Minimal repro via Python bindings:

$ python3 -c 'import MaterialX as mx; d = mx.createDocument(); b = d.addBackdrop(); d.setChildIndex(b.getName(), 1)'
Segmentation fault

Expected behavior:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
LookupError: Invalid child index

Fix:

-    if (index < 0 || index > (int) _childOrder.size())
+    if (index < 0 || index >= (int) _childOrder.size())
     {
         throw Exception("Invalid child index");
     }

Found while working on #342

@jstone-lucasfilm
Copy link
Member

This looks like a good catch, thanks @StefanHabel, and feel free to post your fix if you have the bandwidth!

StefanHabel added a commit to StefanHabel/MaterialX that referenced this issue Oct 22, 2023
Extended the existing test case:
valid values for `index` in the test case are `0` and `1` only.

Minimal repro via Python bindings:
```bash
$ python3 -c 'import MaterialX as mx; d = mx.createDocument(); b = d.addBackdrop(); d.setChildIndex(b.getName(), 1)'
```
Without this patch:
```bash
Segmentation fault
```
With this patch:
```python
Traceback (most recent call last):
  File "<string>", line 1, in <module>
LookupError: Invalid child index
```

Ran the tests locally via `make && make test`:
```bash
100% tests passed, 0 tests failed out of 73
```

Update AcademySoftwareFoundation#1581

Signed-off-by: Stefan Habel <[email protected]>
@jstone-lucasfilm
Copy link
Member

Thanks for this report, @StefanHabel, as well as for the fix in #1582!

@StefanHabel
Copy link
Contributor Author

Thanks very much @jstone-lucasfilm ! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants