-
Notifications
You must be signed in to change notification settings - Fork 84
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
StringIndexOutOfBoundsException cause by long lines in log #267
Comments
@bewinsnw Thanks for the report and for digging up the root cause - care to write a test/and maybe even a fix? |
Well, it's hard to figure out what the tests in there are trying to achieve, since it's all pretty much comment-free. I can see by poking at it that the error condition I'm hitting is triggered by removing a bunch of characters from ansicolor-plugin/src/test/java/hudson/plugins/ansicolor/action/ShortlogActionCreatorTest.java Line 165 in c3e5742
:%s,ha:////[A-Za-z0-9+]\{5},ha:////,g . (removing characters from the ha url, since they didn't seem significant to the algorithm where others might)
This results in:
And the fix to ansicolor-plugin/src/main/java/hudson/plugins/ansicolor/action/ShortlogActionCreator.java Lines 105 to 111 in c3e5742
However, this ends up with:
... which takes me into the weeds trying to understand what's going on with how these tests are structured, LineIdentifier, ColorizedAction, etc, and I don't have the spare cycles to take this further. |
Thanks @bewinsnw, hopefully someone can finish this. |
Jenkins and plugins versions report
Environment
What Operating System are you using (both controller, and any agents involved in the problem)?
controller is running in k8s using the official jenkins helm chart. Agents are AWS Linux 2023.
Reproduction steps
Don't have a direct reproducer but I can see the bug in your code. We're getting this error (which crashed jenkins):
(due to a logging misconfig, we're getting jumbled stacktraces, I'll spare you the rest of the jigsaw, but it's clear from the stacktrace that this is what's at the top).
Expected Results
Jenkins should not crash when ansicolor gets a long line to highlight.
Actual Results
Jenkins crashed.
Anything else?
Looking at the exception, the problem is that
count -16381
, none of the arguments to the strong constructor are allowed to be negative (per JDK docs).Looking at findLastActionBefore we can see it gets those arguments by calling calculateBeginLength, and just quick look at the code there shows an obvious bug
ansicolor-plugin/src/main/java/hudson/plugins/ansicolor/action/ShortlogActionCreator.java
Line 108 in c3e5742
indexOfEol() can return -1. When that happens and keepLinesWhole is true, and eol.length is 1, this function will return
new int[]{begin, -begin}
- which is exactly what we saw logged.That can happen when the eol is past the end of the buffer; in this case, the start of the search was just shy of the end of the 16k buffer and unless any of the next 3 bytes were EOL this is what would happen.
Now we've seen what the bug is, we'll be working around it by disabling keeplineswhole. I expect the better solution would be to treat keeplineswhole as a hint and ignore it if the EOL can't be found.
The text was updated successfully, but these errors were encountered: