fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.11k stars 140 forks source link

`WindowsAnsiOutputStream.processDownCursor` overflows #69

Closed lacasseio closed 7 years ago

lacasseio commented 7 years ago

The method processDownCursor can overflow the cursor position by potentially setting the cursor to info.size.y which is an invalid position. This will cause an ERROR_INVALID_PARAMETER error to be returned from SetConsoleCursorPosition.

The solution (not yet tested) to this last issue would be to replace processCursorDown with the following code:

    protected void processCursorDown(int count) throws IOException {
        getConsoleInfo();
        info.cursorPosition.y = (short) Math.min(Math.max(0, info.size.y - 1), info.cursorPosition.y + count);
        applyCursorPosition();
    }

For more information, see this comment on https://github.com/gradle/gradle/issues/882.

lacasseio commented 7 years ago

@chirino Would you be willing to accept and pushing the previous fix quickly? This is blocking the https://github.com/gradle/gradle/issues/882 for us and it would be a waste if we would need to fork the repo just to do the fix.

lacasseio commented 7 years ago

I opened a PR that fix the problem.

lacasseio commented 7 years ago

I will reopen as the issue still exists in Jansi, workaround was done in Gradle.