Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect readLine() against DoS #144

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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.lsposed.manager.ui.dialog;

import io.github.pixee.security.BoundedLineReader;
import static org.lsposed.manager.App.TAG;

import android.content.Context;
Expand Down Expand Up @@ -119,7 +120,7 @@ private void flash(View view, Button button) {
var inputStream = new ParcelFileDescriptor.AutoCloseInputStream(readSide);
var reader = new BufferedReader(new InputStreamReader(inputStream));

for (var line = ""; line != null; line = reader.readLine()) {
for (var line = ""; line != null; line = BoundedLineReader.readLine(reader, 5_000_000)) {
if (line.length() > 0) {
var showLine = line + "\n";
view.post(() -> {
Expand Down
3 changes: 2 additions & 1 deletion daemon/src/main/java/org/lsposed/lspd/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.ServiceManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import io.github.pixee.security.BoundedLineReader;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -75,7 +76,7 @@ private void printLog(ParcelFileDescriptor parcelFileDescriptor) {
while (true) {
String sLine;
try {
sLine = br.readLine();
sLine = BoundedLineReader.readLine(br, 5_000_000);
} catch (IOException ioe) { break; }
if (sLine == null) {
if (bFollow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.lsposed.lspd.service;

import io.github.pixee.security.BoundedLineReader;
import static org.lsposed.lspd.service.ServiceManager.TAG;
import static org.lsposed.lspd.service.ServiceManager.toGlobalNamespace;

Expand Down Expand Up @@ -366,7 +367,7 @@ private static void readName(ZipFile apkFile, String initName, List<String> name
try (var in = apkFile.getInputStream(initEntry)) {
var reader = new BufferedReader(new InputStreamReader(in));
String name;
while ((name = reader.readLine()) != null) {
while ((name = BoundedLineReader.readLine(reader, 5_000_000)) != null) {
name = name.trim();
if (name.isEmpty() || name.startsWith("#")) continue;
names.add(name);
Expand Down