Skip to content

Fix blend render returning empty result #123

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

Merged
merged 1 commit into from
Feb 4, 2022

Conversation

dmitrylyzo
Copy link
Contributor

@dmitrylyzo dmitrylyzo commented Jan 31, 2022

libass may return empty images, and 'blendResult' may become invalid (with zero height), leading to a runtime error when displaying.
Noticed on 'Railgun S Karaoke Test' ~26.38s (after the first verse) with dropAllAnimations enabled.

Would checking <= 0 be better, since width and height are int?
They probably can't be negative by design, but... 🤔

This seems to be reproduced with wasm-blend on empty_image.ass.txt

@TheOneric
Copy link
Member

TheOneric commented Feb 3, 2022

Thanks! Can you be more verbose in your description on why and how exactly a zero width image leads to runtime errors later?

Would checking <= 0 be better, since width and height are int?
They probably can't be negative by design, but... 🤔

Internally the positions (but not the extnents afaik) can be negative, but before the images are returned to the API-user libass clips them to the positive range. Negative values being returned would be a libass bug and this is also relied upon by mpv. So this is safe.

On a side note, I find it a bit odd to always subtract 1 just to later readd 1. If it's to avoid signed-overflows, imho using unsigned is the better option. Either way this isn't directly harmful and unrelated to the bug being addressed here.

@dmitrylyzo
Copy link
Contributor Author

dmitrylyzo commented Feb 3, 2022

Uncaught DOMException: Failed to construct 'ImageData': The source height is zero or not a number.

Internally the positions (but not the extnents afaik) can be negative, but before the images are returned to the API-user libass clips them to the positive range. Negative values being returned would be a libass bug and this is also relied upon by mpv. So this is safe.

👍

On a side note, I find it a bit odd to always subtract 1 just to later readd 1. If it's to avoid signed-overflows, imho using unsigned is the better option. Either way this isn't directly harmful and unrelated to the bug being addressed here.

I think this is to get the exact right pixel: x + w - 1 because x + w is an outer pixel.
I haven't looked too deep, you are probably right and +-1 can be safely removed.

@TheOneric
Copy link
Member

Uncaught DOMException: Failed to construct 'ImageData': The source height is zero or not a number.

[In the commit message:] [...] leading to a runtime error when displaying, being unable to create an image with zero or invalid size.

I think the commit message could still be a bit more explicit naming what API can't create zero-area images, e.g.:

libass may return empty images, but browsers do not allow
creation of zero-area ImageData objects. Skipping and
exiting early on empty images avoids this and as a bonus
also saves a few CPU-cycles.

Initially noticed on the 'Railgun S Karaoke Test' sample
at ~26.38s (after the first verse) with `dropAllAnimations`
from jellyfin enabled.

Otherwise this seems good to merge to me, thanks.

libass may return empty images, but browsers do not allow
creation of zero-area ImageData objects. Skipping and
exiting early on empty images avoids this and as a bonus
also saves a few CPU-cycles.

Initially noticed on the 'Railgun S Karaoke Test' sample
at ~26.38s (after the first verse) with `dropAllAnimations`
from jellyfin enabled.
@TheOneric TheOneric merged commit 816e104 into libass:master Feb 4, 2022
@dmitrylyzo dmitrylyzo deleted the fix-empty-blend branch February 4, 2022 18:45
@TheOneric TheOneric added the bug label Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants