mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Fixed: Fix ArrayIndexOutOfBoundsException when setting zero width terminal character
java.lang.ArrayIndexOutOfBoundsException: length=64; index=-1 at com.termux.terminal.TerminalRow.setChar(TerminalRow.java:127) at com.termux.terminal.TerminalBuffer.setChar(TerminalBuffer.java:413) at com.termux.terminal.TerminalEmulator.emitCodePoint(TerminalEmulator.java:2329) at com.termux.terminal.TerminalEmulator.processCodePoint(TerminalEmulator.java:617) at com.termux.terminal.TerminalEmulator.processByte(TerminalEmulator.java:513) at com.termux.terminal.TerminalEmulator.append(TerminalEmulator.java:480) at com.termux.terminal.TerminalSession$MainThreadHandler.handleMessage(TerminalSession.java:339) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8349) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
This commit is contained in:
@@ -449,8 +449,8 @@ public final class TerminalBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setChar(int column, int row, int codePoint, long style) {
|
public void setChar(int column, int row, int codePoint, long style) {
|
||||||
if (row >= mScreenRows || column >= mColumns)
|
if (row < 0 || row >= mScreenRows || column < 0 || column >= mColumns)
|
||||||
throw new IllegalArgumentException("row=" + row + ", column=" + column + ", mScreenRows=" + mScreenRows + ", mColumns=" + mColumns);
|
throw new IllegalArgumentException("TerminalBuffer.setChar(): row=" + row + ", column=" + column + ", mScreenRows=" + mScreenRows + ", mColumns=" + mColumns);
|
||||||
row = externalToInternalRow(row);
|
row = externalToInternalRow(row);
|
||||||
allocateFullLineIfNecessary(row).setChar(column, codePoint, style);
|
allocateFullLineIfNecessary(row).setChar(column, codePoint, style);
|
||||||
}
|
}
|
||||||
|
@@ -2332,7 +2332,14 @@ public final class TerminalEmulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int offsetDueToCombiningChar = ((displayWidth <= 0 && mCursorCol > 0 && !mAboutToAutoWrap) ? 1 : 0);
|
int offsetDueToCombiningChar = ((displayWidth <= 0 && mCursorCol > 0 && !mAboutToAutoWrap) ? 1 : 0);
|
||||||
mScreen.setChar(mCursorCol - offsetDueToCombiningChar, mCursorRow, codePoint, getStyle());
|
int column = mCursorCol - offsetDueToCombiningChar;
|
||||||
|
|
||||||
|
// Fix TerminalRow.setChar() ArrayIndexOutOfBoundsException index=-1 exception reported
|
||||||
|
// The offsetDueToCombiningChar would never be 1 if mCursorCol was 0 to get column/index=-1,
|
||||||
|
// so was mCursorCol changed after the offsetDueToCombiningChar conditional by another thread?
|
||||||
|
// TODO: Check if there are thread synchronization issues with mCursorCol and mCursorRow, possibly causing others bugs too.
|
||||||
|
if (column < 0) column = 0;
|
||||||
|
mScreen.setChar(column, mCursorRow, codePoint, getStyle());
|
||||||
|
|
||||||
if (autoWrap && displayWidth > 0)
|
if (autoWrap && displayWidth > 0)
|
||||||
mAboutToAutoWrap = (mCursorCol == mRightMargin - displayWidth);
|
mAboutToAutoWrap = (mCursorCol == mRightMargin - displayWidth);
|
||||||
|
@@ -124,6 +124,9 @@ public final class TerminalRow {
|
|||||||
|
|
||||||
// https://github.com/steven676/Android-Terminal-Emulator/commit/9a47042620bec87617f0b4f5d50568535668fe26
|
// https://github.com/steven676/Android-Terminal-Emulator/commit/9a47042620bec87617f0b4f5d50568535668fe26
|
||||||
public void setChar(int columnToSet, int codePoint, long style) {
|
public void setChar(int columnToSet, int codePoint, long style) {
|
||||||
|
if (columnToSet < 0 || columnToSet >= mStyle.length)
|
||||||
|
throw new IllegalArgumentException("TerminalRow.setChar(): columnToSet=" + columnToSet + ", codePoint=" + codePoint + ", style=" + style);
|
||||||
|
|
||||||
mStyle[columnToSet] = style;
|
mStyle[columnToSet] = style;
|
||||||
|
|
||||||
final int newCodePointDisplayWidth = WcWidth.width(codePoint);
|
final int newCodePointDisplayWidth = WcWidth.width(codePoint);
|
||||||
|
Reference in New Issue
Block a user