Skip to content

Commit

Permalink
Catch another out of memory error in image code
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanZ committed Oct 10, 2024
1 parent d607bf6 commit 7e0f523
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public TerminalBitmap(int num, byte[] image, int Y, int X, int cellW, int cellH,
} else {
try {
bm = BitmapFactory.decodeByteArray(image, 0, image.length);
} catch (Exception e) {
} catch (OutOfMemoryError e) {
Logger.logWarn(null, LOG_TAG, "Out of memory, cannot decode image");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public final class TerminalEmulator {
private boolean ESC_P_sixel = false;
private ArrayList<Byte> ESC_OSC_data;
private int ESC_OSC_colon = 0;
private boolean ESC_OSC_outofmem = false;

private final SavedScreenState mSavedStateMain = new SavedScreenState();
private final SavedScreenState mSavedStateAlt = new SavedScreenState();
Expand Down Expand Up @@ -2089,14 +2090,21 @@ private void doOsc(int b) {
// Collect base64 data for OSC 1337
ESC_OSC_colon = mOSCOrDeviceControlArgs.length();
ESC_OSC_data = new ArrayList<Byte>(65536);
ESC_OSC_outofmem = false;
} else if (ESC_OSC_colon >= 0 && mOSCOrDeviceControlArgs.length() - ESC_OSC_colon == 4) {
if (!ESC_OSC_outofmem) {
try {
byte[] decoded = Base64.decode(mOSCOrDeviceControlArgs.substring(ESC_OSC_colon), 0);
for (int i = 0 ; i < decoded.length; i++) {
ESC_OSC_data.add(decoded[i]);
}
} catch(Exception e) {
// Ignore non-Base64 data.
} catch(OutOfMemoryError e) {
// Out of memory
// Keep decoding, but fo not collect the data
ESC_OSC_outofmem = true;
}
}
mOSCOrDeviceControlArgs.setLength(ESC_OSC_colon);

Expand Down

0 comments on commit 7e0f523

Please sign in to comment.