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

Self-reference to $this in PelIfd::$maker_notes #6

Open
saemy opened this issue Oct 4, 2023 · 2 comments · May be fixed by #7
Open

Self-reference to $this in PelIfd::$maker_notes #6

saemy opened this issue Oct 4, 2023 · 2 comments · May be fixed by #7

Comments

@saemy
Copy link

saemy commented Oct 4, 2023

PelIfd::$maker_notes["parent"] is always $this (there is only one caller of PelIfd::setMakerNotes()). However, adding $this to the array leads to a reference of a PelIfd instance to itself. As a result that PelIfd instance can not be cleaned up right away after all references to it go away (as the ref_count remains at 1 - the one to itself). Only at garbage collection time the garbage cycle is detected and that instance is cleaned up.

This is an issue in case big images are processed one after another. In that scenario PelIfd::$maker_notes['data'] contains the full image data (i.e. multiple MB) and is only released upon garbage collection time - which is not right away. Garbage memory is piling up and running out of memory is easily possible and the program might crash with "Fatal error: Allowed memory size of xxx bytes exhausted".

saemy added a commit to saemy/pel that referenced this issue Oct 4, 2023
`PelIfd::$maker_notes["parent"]` is always `$this` (there is only one caller of
`PelIfd::setMakerNotes()`). However, adding `$this` to the array leads to a
reference of a `PelIfd` instance to itself. As a result that `PelIfd` instance
can not be cleaned up right away after all references to it go away (as the
ref_count remains at 1 - the one to itself).
Only at garbage collection time the garbage cycle is detected and that instance
is cleaned up.

This is an issue in case big images are processed one after another. In that
scenario `PelIfd::$maker_notes['data']` contains the full image data (i.e.
multiple MB) and is only released upon garbage collection time - which is not
right away. Garbage memory is piling up and running out of memory is easily
possible and the program might crash with `"Fatal error:  Allowed memory size
of xxx bytes exhausted"`.

Removes the self-reference in the `PelIfd::$maker_notes` array.

fixes: FileEye#6
@saemy saemy linked a pull request Oct 4, 2023 that will close this issue
@devbranch-vitaliy
Copy link

devbranch-vitaliy commented Dec 5, 2023

The same thing!
I tried to fix the issue with #7 but it didn't help me, the issue is still reproducible
In my case, more than 15 Jpeg images are processed one after another.
At the very least, we must provide protection against an infinite loop.

@saemy
Copy link
Author

saemy commented Dec 12, 2023

@devbranch-vitaliy Can you share one of those images s.t. I can try to reproduce? Thank you.

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

Successfully merging a pull request may close this issue.

2 participants