Skip to content

Fix potential memory leak in SceneCombiner for LWS/IRR/MD3 loader - #5721

Merged
kimkulling merged 7 commits into
assimp:masterfrom
TinyTinni:lws-leak
Aug 29, 2024
Merged

kimkulling merged 7 commits into
assimp:masterfrom
TinyTinni:lws-leak

Conversation

@TinyTinni

Copy link
Copy Markdown
Contributor

Maybe fixes #4231

(fuzzer says, it is a NULL read, but when trying the file, I get a memory leak. Also, in the issue, you also tried to fix some memory leak there. Therefore, not really sure, a bit confusing).

Short explanation about the fix:

SceneCombiner::MergeScenes guarantees by the documentation, that the master parameter is cleaned up afterwards:

@ param master Master scene. It will be deleted afterwards. All
other scenes will be inserted in its node graph.

This should also include, when the destination is null (case 1. the first inserted delete).

For this bug, it should also clean up, if the scene is copied.

CopySceneFlat does not clean up the source according to the documentation:

@ param src Source scene - remains unmodified.

Therefore, the cleanup duty should be in MergeScenes.


I also checked other usage of MergeScene outside of LWS loader.

It is also used in

  • IRRLoader: here, the tempscene which is used for the master parameter is also not cleaned up -> no risk of double free + also potential leak fix link to the line
  • MD3Loader: here, the master is also not cleaned up, just in error case, which is not possible after MergeScene -> no risk of double free + also potential leak fix link to the line

For the later 2 issues, I couldn't find any fuzzer bug issue but clang-analyzer complains there too about a potential leak.

@TinyTinni

Copy link
Copy Markdown
Contributor Author

Also deletes the sourcelist.

@ param src Non-empty list of scenes to be merged along with their
corresponding attachment points in the master scene. The function
deletes the input scenes afterwards. There may be duplicate scenes.

@TinyTinni
TinyTinni force-pushed the lws-leak branch 2 times, most recently from ff23d6d to c89fac6 Compare August 17, 2024 14:26
@turol

turol commented Aug 17, 2024

Copy link
Copy Markdown
Member

Why set? Why not unordered_set? Does iteration order matter?

Why do you check for nullptr? It's safe to call delete on a null pointer. If you really want the check you should do it while inserting to avoid a tiny bit of useless work.

@TinyTinni

Copy link
Copy Markdown
Contributor Author

Why set? Why not unordered_set? Does iteration order matter?

Why do you check for nullptr? It's safe to call delete on a null pointer. If you really want the check you should do it while inserting to avoid a tiny bit of useless work.

Thanks for the feedback, I fixed it.

@kimkulling kimkulling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks not bad. Hard to find I guess.

@kimkulling
kimkulling merged commit 3e7e4c8 into assimp:master Aug 29, 2024
@kimkulling

Copy link
Copy Markdown
Member

Merged, thanks a lot for your contribution.

@TinyTinni
TinyTinni deleted the lws-leak branch August 29, 2024 12:15
kimkulling added a commit that referenced this pull request Jul 1, 2026
)

* fix potential memory leak in scenecombiner

* also cleansup srclist

* de-duplicates before deleting

---------

Co-authored-by: Kim Kulling <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Bug: Issue 39595 in oss-fuzz: assimp:assimp_fuzzer: Null-dereference READ in Assimp::LWSImporter::BuildGraph

3 participants