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

Introduced protections against DoS via unterminated read operations #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions src/main/java/com/github/gilday/darkmode/DarkModeDetector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.gilday.darkmode;

import io.github.pixee.security.BoundedLineReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -22,9 +23,9 @@ static boolean isMacOsDarkMode() {
new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stderrReader =
new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
final String stdout = stdoutReader.readLine();
stderrReader.readLine(); // skip first line of output
final String stderr = stderrReader.readLine();
final String stdout = BoundedLineReader.readLine(stdoutReader, 1000000);
BoundedLineReader.readLine(stderrReader, 1000000); // skip first line of output
final String stderr = BoundedLineReader.readLine(stderrReader, 1000000);
if ("Dark".equals(stdout)) {
return true;
}
Expand Down Expand Up @@ -55,9 +56,9 @@ static Boolean isWindowsDarkMode() {

try (BufferedReader stdoutReader =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {
stdoutReader.readLine();
stdoutReader.readLine();
final String stdout = stdoutReader.readLine();
BoundedLineReader.readLine(stdoutReader, 1000000);
BoundedLineReader.readLine(stdoutReader, 1000000);
final String stdout = BoundedLineReader.readLine(stdoutReader, 1000000);
if (stdout.endsWith("0")) {
return true;
} else if (stdout.endsWith("1")) {
Expand Down