Skip to content

Protect readLine() against DoS #30

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

Open
wants to merge 1 commit into
base: master
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 @@ -28,6 +28,7 @@
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.EncryptionUtils;
import io.github.pixee.security.BoundedLineReader;

import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpMethodBase;
Expand Down Expand Up @@ -489,10 +490,10 @@ private static String inputStreamToString(InputStream inputStream) {
try {
StringBuilder total = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = reader.readLine();
String line = BoundedLineReader.readLine(reader, 5_000_000);
while (line != null) {
total.append(line).append('\n');
line = reader.readLine();
line = BoundedLineReader.readLine(reader, 5_000_000);
}
return total.toString();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.AsyncTask;

import com.owncloud.android.lib.common.utils.Log_OC;
import io.github.pixee.security.BoundedLineReader;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -35,7 +36,7 @@ protected Integer doInBackground(String... args) {
URL url = new URL(args[0]);
final Charset charset = Charset.defaultCharset();
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), charset))) {
return Integer.parseInt(in.readLine());
return Integer.parseInt(BoundedLineReader.readLine(in, 5_000_000));

} catch (IOException e) {
Log_OC.e(TAG, "Error loading version number", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.UriUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import io.github.pixee.security.BoundedLineReader;

import org.greenrobot.eventbus.EventBus;

Expand Down Expand Up @@ -141,7 +142,7 @@ private String getUrlFromFile(String storagePath, Pattern pattern) {
br = new BufferedReader(fr);

String line;
while ((line = br.readLine()) != null) {
while ((line = BoundedLineReader.readLine(br, 5_000_000)) != null) {
Matcher m = pattern.matcher(line);
if (m.find()) {
url = m.group(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.owncloud.android.utils.svg.SvgDecoder;
import com.owncloud.android.utils.svg.SvgDrawableTranscoder;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import io.github.pixee.security.BoundedLineReader;

import org.greenrobot.eventbus.EventBus;

Expand Down Expand Up @@ -620,7 +621,7 @@ public static String getData(InputStream inputStream) {
String line;
StringBuilder text = new StringBuilder();
try {
while ((line = buffreader.readLine()) != null) {
while ((line = BoundedLineReader.readLine(buffreader, 5_000_000)) != null) {
text.append(line);
text.append('\n');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.owncloud.android.lib.resources.status.SendClientDiagnosticRemoteOperation;
import com.owncloud.android.operations.UploadException;
import com.owncloud.android.utils.theme.CapabilityUtils;
import io.github.pixee.security.BoundedLineReader;

import org.apache.commons.httpclient.HttpStatus;

Expand Down Expand Up @@ -1200,7 +1201,7 @@ public static ArrayList<String> getRandomWords(int count, Context context) throw

List<String> lines = new ArrayList<>();
String line;
while ((line = bufferedReader.readLine()) != null) {
while ((line = BoundedLineReader.readLine(bufferedReader, 5_000_000)) != null) {
lines.add(line);
}

Expand Down
Loading