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

Fix OutOfMemoryError when using TailTipWidget (fixes #974) #975

Merged
merged 1 commit into from Apr 24, 2024

Conversation

VerKWer
Copy link
Contributor

@VerKWer VerKWer commented Apr 23, 2024

Issue #974 (OutOfMemoryError when enabling a TailTipWidget in a terminal of size 0x0) is caused by the new Status.getBorderString method, which tries to create a string that's '─' repeated 2_147_483_646 times.

The underlying reason why we even get into that situation is Display.resize, which interprets a size of 0x0 (which happens e.g. in a detached container) as 1x(Integer.MAX_VALUE-1). I understand that zero values might be problematic, and an old issue that is linked to that change mentions some arithmetic exception due to a division by zero. I'm not sure, however, why Integer.MAX_VALUE - 1 was chosen. My guess is that a value of 1 (same as for the rows) is safer, and some unsystematic tests using existing applications didn't reveal any issues (e.g. when resizing).

I also added an additional check in Status.update to check if we have more than one row before even starting to draw anything. If there is only one row, there is no space for a border and text below it. This change in and of itself would already be sufficient, I believe. So if that Integer.MAX_VALUE - 1 serves a function, it can be restored.

Finally, I added a small unit test reproducing the problem in issue #974, which passes now with the added fixes.

Copy link
Member

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

Very nice work, thx a ton !

@gnodet gnodet added this to the 3.26.1 milestone Apr 24, 2024
@gnodet gnodet merged commit 1ab69e3 into jline:master Apr 24, 2024
4 checks passed
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 this pull request may close these issues.

None yet

2 participants