OutputStreamMonitor.getContents() inserts U+FFFD when a multibyte character is split across two reads
Los mantenedores suelen responder en 1 día
@dimitribekale ya está trabajando en esto.
Desde el 5/11/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
Start with debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java, especially getContents(), flushContents(), and setBuffered(), and read the related OutputStreamMonitorTests coverage. Reproduce the split UTF-8 read described in the issue and check how decoding behaves when getContents() is called after each read. Done means the returned text is o and then oöO without an intervening flush, while the existing flush test still passes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
org.eclipse.debug.internal.core.OutputStreamMonitor.getContents() returns corrupted text when a
multibyte character arrives split across two reads of the process stream and getContents() is
called after each read without flushContents() in between.
Cause. getContents() (master c49150d04204, 2026-11-04, lines 191–202) decodes the whole accumulated byte
buffer with fBufferedDecoder, a stateful StreamDecoder that keeps the bytes of an incomplete
trailing character between calls. The read thread clears fCachedDecodedContents on every append,
so the next call re-feeds bytes the decoder has already consumed. The retained lead byte is then
followed by the first byte of the buffer again, which the decoder reports as malformed input (U+FFFD).
Reproduce. UTF-8 monitor, input "oöO" (6F C3 B6 4F), written as 6F C3 then B6 4F,
getContents() after each write (the attached Repro.java does this with a PipedOutputStream and
the same subclass trick as OutputStreamMonitorTests):
- Expected:
"o", then"oöO" - Actual:
"o", then"�oöO"
The existing testBufferedOutputStreamMonitor uses this input but flushes between the reads, so it
does not catch the case.
Impact. IStreamMonitor.getContents() is API and monitors are buffered from construction.
ProcessConsole reads the contents once and then unbuffers, so the Console view is not affected;
clients that poll a buffered monitor while the process is writing get wrong text. Minor.
Proposed fix. Decode only the bytes not yet fed to the decoder and accumulate the result, so
nothing is re-fed; flushContents() and setBuffered() reset the accumulated text and the fed-byte
count and keep the decoder state, as today. Verified fail-then-pass against master compiled
standalone, and the flush sequence of testBufferedOutputStreamMonitor keeps its current result.
A regression test in the style of that test is included below. Happy to open a PR if this is
confirmed.
Patch
--- a/debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java
+++ b/debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java
@@ -70,7 +70,9 @@
* of an incomplete character.
*/
private StreamDecoder fBufferedDecoder;
+ /** Decoded form of the first {@link #fDecodedLength} bytes of {@link #fContents}. */
private String fCachedDecodedContents;
+ private int fDecodedLength;
/**
* The thread which reads from the stream
@@ -193,11 +195,12 @@
if (!isBuffered()) {
return ""; //$NON-NLS-1$
}
- if (fCachedDecodedContents != null) {
- return fCachedDecodedContents;
- }
byte[] data = getData();
- fCachedDecodedContents = fBufferedDecoder.decode(data, 0, data.length);
+ if (fDecodedLength < data.length) {
+ // decode only the bytes not yet fed to the stateful decoder
+ fCachedDecodedContents += fBufferedDecoder.decode(data, fDecodedLength, data.length - fDecodedLength);
+ fDecodedLength = data.length;
+ }
return fCachedDecodedContents;
}
@@ -236,7 +239,6 @@
if (read > 0) {
synchronized (this) {
if (isBuffered()) {
- fCachedDecodedContents = null;
fContents.write(buffer, 0, read);
}
fireStreamAppended(buffer, 0, read);
@@ -306,7 +308,8 @@
@Override
public synchronized void setBuffered(boolean buffer) {
if (isBuffered() != buffer) {
- fCachedDecodedContents = null;
+ fCachedDecodedContents = ""; //$NON-NLS-1$
+ fDecodedLength = 0;
if (buffer) {
fContents = new ByteArrayOutputStream();
fBufferedDecoder = new StreamDecoder(fCharset == null ? Charset.defaultCharset() : fCharset);
@@ -320,7 +323,8 @@
@Override
public synchronized void flushContents() {
if (isBuffered()) {
- fCachedDecodedContents = null;
+ fCachedDecodedContents = ""; //$NON-NLS-1$
+ fDecodedLength = 0;
fContents.reset();
}
}
Regression test for OutputStreamMonitorTests
/**
* A multibyte character split across two reads must not be corrupted when
* getContents() is called after each read without flushing in between.
*/
@Test
public void testBufferedContentsWithSplitCharacterAndNoFlush() throws Exception {
String input = "oöO";
byte[] byteInput = input.getBytes(StandardCharsets.UTF_8);
BinaryListener binaryListener = new BinaryListener();
monitor.addBinaryListener(binaryListener);
sysout.write(byteInput, 0, 2);
sysout.flush();
monitor.startMonitoring();
binaryListener.waitForBytes(2);
assertThat(monitor.getContents()).isEqualTo(input.substring(0, 1));
sysout.write(byteInput, 2, byteInput.length - 2);
sysout.flush();
binaryListener.waitForBytes(byteInput.length);
assertThat(monitor.getContents()).isEqualTo(input);
binaryListener.assertNoExceptions();
}
Standalone reproducer (Repro.java)
Compile OutputStreamMonitor.java and StreamDecoder.java from master together with this file
against the Eclipse SDK plug-ins (JDK 17+), run Repro; exit code 1 on the current code, 0 with
the patch.
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.StandardCharsets;
import org.eclipse.debug.core.IBinaryStreamListener;
import org.eclipse.debug.internal.core.OutputStreamMonitor;
public class Repro {
static class TestOutputStreamMonitor extends OutputStreamMonitor {
TestOutputStreamMonitor(java.io.InputStream in) { super(in, StandardCharsets.UTF_8); }
public void startMonitoring() { super.startMonitoring("repro"); }
}
public static void main(String[] args) throws Exception {
String input = "oöO";
byte[] bytes = input.getBytes(StandardCharsets.UTF_8); // 6F C3 B6 4F
PipedOutputStream sysout = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(sysout);
TestOutputStreamMonitor monitor = new TestOutputStreamMonitor(in);
int[] received = {0};
monitor.addBinaryListener((IBinaryStreamListener) (data, m) -> { synchronized (received) { received[0] += data.length; received.notifyAll(); } });
sysout.write(bytes, 0, 2); // 'o' + first byte of 'ö'
sysout.flush();
monitor.startMonitoring();
waitFor(received, 2);
String first = monitor.getContents(); // "o", decoder keeps 0xC3
sysout.write(bytes, 2, 2); // second byte of 'ö' + 'O', no flushContents in between
sysout.flush();
waitFor(received, 4);
String second = monitor.getContents();
sysout.close();
System.out.println("first getContents(): " + show(first));
System.out.println("second getContents(): " + show(second) + " expected " + show(input));
System.exit(second.equals(input) ? 0 : 1);
}
static void waitFor(int[] c, int n) throws InterruptedException {
synchronized (c) { long end = System.currentTimeMillis() + 10000; while (c[0] < n && System.currentTimeMillis() < end) c.wait(100); }
}
static String show(String s) {
StringBuilder b = new StringBuilder("\"");
for (char ch : s.toCharArray()) b.append(ch < 128 ? String.valueOf(ch) : String.format("<U+%04X>", (int) ch));
return b.append('"').toString();
}
}
Provenance. This defect was found during an academic study of LLM-assisted code review at Jeonbuk National University (Jeonju, South Korea). The initial analysis was produced by an automated LLM-based reviewer and then manually verified by the authors: we confirmed the defect mechanism by reading the source at HEAD, and the reproducer above compiles and exhibits the failure against the real code. The reviewer's own patch (a fresh decoder per call) fixed this case but broke the flush sequence that the existing testBufferedOutputStreamMonitor asserts, so the patch proposed here is the authors' correction. We are disclosing this origin in line with project policies on AI-assisted contributions. We report it because we believe it is a genuine defect, and we will respect the project's triage either way; a "not a bug" outcome is valuable to us as a correction.
- Lenguaje dominante
- Java
- Estrellas
- 165
- Forks
- 174
- Merge medio
- 4 d 56 min
- PR fusionados (30 d)
- 36
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de eclipse-platform/eclipse.platform
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
eclipse-platform/eclipse.platform#3019 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
eclipse-platform/eclipse.platform#2940 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
eclipse-platform/eclipse.platform#2593 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
-
test
Dificultad 3/5 1-2 días Aptitud para principiantes 57/100
eclipse-platform/eclipse.platform#3057 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
eclipse-platform/eclipse.platform#3027 ·
Los mantenedores suelen responder en 1 día
Todos los issues de eclipse-platform/eclipse.platform
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
Flaky TunnelClientTest: fake server keeps sending fragments after the client closes the tunnelAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
MetricsHub/metricshub-community#1532 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
asciidoctor/asciidoctor-intellij-plugin#2157 ·
Los mantenedores suelen responder en 4 días
-
account bug exercise lecture
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
MinGW fails to compile simulatorAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
rusefi/rusefi#10602 · 1 comentario ·
Los mantenedores suelen responder en 1 día