Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Protect readLine() against DoS #403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ dependencies {
implementation "com.google.accompanist:accompanist-systemuicontroller:0.32.0"
implementation "org.lsposed.hiddenapibypass:hiddenapibypass:4.3"
implementation "com.google.code.gson:gson:2.10.1"
implementation("io.github.pixee:java-security-toolkit:1.0.7")

implementation roots.AndroidXCore
implementation roots.AndroidXCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.sevtinge.cemiuiler.R;
import com.sevtinge.cemiuiler.utils.ShellUtils;
import com.sevtinge.cemiuiler.utils.TileUtils;
import io.github.pixee.security.BoundedLineReader;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand Down Expand Up @@ -277,7 +278,7 @@ public String readAndWrit(String writ, boolean need) {
try {
reader = new BufferedReader(new FileReader(path));
builder = new StringBuilder();
while ((line = reader.readLine()) != null) {
while ((line = BoundedLineReader.readLine(reader, 5_000_000)) != null) {
builder.append(line);
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.net.Uri;

import androidx.annotation.Nullable;
import io.github.pixee.security.BoundedLineReader;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -62,10 +63,10 @@ public static void handleReadDocument(Activity activity, @Nullable Uri data) thr
InputStream inputStream = activity.getContentResolver().openInputStream(data);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
String line = bufferedReader.readLine();
String line = BoundedLineReader.readLine(bufferedReader, 5_000_000);
while (line != null) {
stringBuilder.append(line);
line = bufferedReader.readLine();
line = BoundedLineReader.readLine(bufferedReader, 5_000_000);
}
String read = stringBuilder.toString();
JSONObject jsonObject = new JSONObject(read);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Environment;
import io.github.pixee.security.BoundedLineReader;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void run() {
logcatProc = Runtime.getRuntime().exec(cmds);
mReader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), 1024);
String line = null;
while (mRunning && (line = mReader.readLine()) != null) {
while (mRunning && (line = BoundedLineReader.readLine(mReader, 5_000_000)) != null) {
if (!mRunning) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sevtinge.cemiuiler.utils;

import io.github.pixee.security.BoundedLineReader;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -137,10 +138,10 @@ public static CommandResult execCommand(String[] commands, boolean isRoot, boole
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
while ((s = BoundedLineReader.readLine(successResult, 5_000_000)) != null) {
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
while ((s = BoundedLineReader.readLine(errorResult, 5_000_000)) != null) {
errorMsg.append(s);
}
}
Expand Down