Skip to content

Commit bcc20bf

Browse files
MatanZNadeem Anwar
authored andcommitted
Catch another out of memory error in image code
1 parent 3751762 commit bcc20bf

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

terminal-emulator/src/main/java/com/termux/terminal/TerminalBitmap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public TerminalBitmap(int num, byte[] image, int Y, int X, int cellW, int cellH,
105105
} else {
106106
try {
107107
bm = BitmapFactory.decodeByteArray(image, 0, image.length);
108-
} catch (Exception e) {
108+
} catch (OutOfMemoryError e) {
109109
Logger.logWarn(null, LOG_TAG, "Out of memory, cannot decode image");
110110
}
111111
}

terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public final class TerminalEmulator {
201201
private boolean ESC_P_sixel = false;
202202
private ArrayList<Byte> ESC_OSC_data;
203203
private int ESC_OSC_colon = 0;
204+
private boolean ESC_OSC_outofmem = false;
204205

205206
private final SavedScreenState mSavedStateMain = new SavedScreenState();
206207
private final SavedScreenState mSavedStateAlt = new SavedScreenState();
@@ -2132,14 +2133,21 @@ private void doOsc(int b) {
21322133
// Collect base64 data for OSC 1337
21332134
ESC_OSC_colon = mOSCOrDeviceControlArgs.length();
21342135
ESC_OSC_data = new ArrayList<Byte>(65536);
2136+
ESC_OSC_outofmem = false;
21352137
} else if (ESC_OSC_colon >= 0 && mOSCOrDeviceControlArgs.length() - ESC_OSC_colon == 4) {
2138+
if (!ESC_OSC_outofmem) {
21362139
try {
21372140
byte[] decoded = Base64.decode(mOSCOrDeviceControlArgs.substring(ESC_OSC_colon), 0);
21382141
for (int i = 0 ; i < decoded.length; i++) {
21392142
ESC_OSC_data.add(decoded[i]);
21402143
}
21412144
} catch(Exception e) {
21422145
// Ignore non-Base64 data.
2146+
} catch(OutOfMemoryError e) {
2147+
// Out of memory
2148+
// Keep decoding, but fo not collect the data
2149+
ESC_OSC_outofmem = true;
2150+
}
21432151
}
21442152
mOSCOrDeviceControlArgs.setLength(ESC_OSC_colon);
21452153

0 commit comments

Comments
 (0)