Avoid self-copy data loss in avifImageCopy()#3234
Conversation
|
Thank you for your interest in libavif. I would consider this as incorrect use of the API and in my opinion there is no need to handle that case nor explain it in the API comment. Why would a user call |
|
@y-guyon Thank you for the clarification. I viewed self-copy as a valid operation because the API does not currently document that the source and destination must be different. My concern was that the function currently returns Would you prefer this to remain undocumented caller responsibility, or would documenting |
|
In API design it seems more elegant to allow self copy and handle it properly, similar to the assignment operator But I agree with Yannis that calling There are two other libavif public functions that take two
|
|
This PR has been replaced by PR #3236. |
Summary
avifImageCopy()does not handle self-copy correctly.When the same image is passed as both source and destination:
the function frees the image planes before copying, causing owned image data to be discarded while still returning
AVIF_RESULT_OK.Fix
Add an early return for self-copy operations:
This preserves existing image data and avoids unnecessary work when the source and destination are the same object.