bevyengine / bevyengine/bevy

Detect immediate asset path loading cycles to prevent stack overflows

Open
#21,691 0 comments 0 reactions 0 assignees View on GitHub
A-Assets C-Bug C-Feature D-Modest S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

An asset loader could cause a stackoverflow by doing an immediate load on its own path: A -> A "Asset A loads asset A". This shallow case was fixed with PR #21619. However, this vulnerability can be re-introduced by having an intermediary asset that loads A -> B -> A.

There are many cases where an asset refers to other files. Any case where an asset might load another asset of its own or ancestors' type is vulnerable to this bug.

## What solution would you like?

It would seem like you'd need to keep a list of asset path ancestors with a `LoadContext` to guard against accidentally loading one of your ancestors. But perhaps there are other ways to detect when a load has already happened. We give out handles paired to a path, so conceivably that state for a load request exists somewhere.

## What alternative(s) have you considered?

You could let the stackoverflow be its own deterrent from creating load cycles.

## Additional context

One further consideration is whether loading an ancestors' path must be an error. For instance if an asset has multiple loaders and asset types it could be interpreted as, one might load an asset as asset type X and within that asset load it again as asset type Y, and that would not necessarily be an error but perhaps a useful means of reusing assets and their loaders. For instance, I have a `SpriteSheet` asset in [Nano-9](https://github.com/shanecelis/nano-9) and its asset path could be 'sprites.png'. The loader either reads the png format itself if it's set to bit-indexed, or it uses Bevy's standard image loader.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.