Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-03-26 00:00:58 +0000
committerPaul Pazderski2019-05-14 08:32:40 +0000
commitbd26d4f1c3635d683d078d9352467c7879571d62 (patch)
treec45c815a32ffbf49e6f4014e1fad0b9cfa2cc822 /org.eclipse.debug.ui/ui/org/eclipse
parent6fd317d247b94e2e4184ff79f665c7eb848ceb6e (diff)
downloadeclipse.platform.debug-bd26d4f1c3635d683d078d9352467c7879571d62.tar.gz
eclipse.platform.debug-bd26d4f1c3635d683d078d9352467c7879571d62.tar.xz
eclipse.platform.debug-bd26d4f1c3635d683d078d9352467c7879571d62.zip
Bug 545769 - [console] UTF-8 content read or send to process can beI20190517-1800I20190516-1800
corrupted With some bad luck the ProcessConsole may disrupt multibyte UTF-8 characters read from input source (usually user input or file) due to incorrect stream reading / buffer handling. The same problem exist for reading the processes output streams. Change-Id: I8d52d1973f3739e2c510a8a4c48b44f345c33dfe Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse')
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java37
1 files changed, 23 insertions, 14 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java
index 6659ef202..04833103c 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Pazderski - Bug 545769: fixed rare UTF-8 character corruption bug
*******************************************************************************/
package org.eclipse.debug.internal.ui.views.console;
@@ -20,6 +21,8 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -740,23 +743,29 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe
@Override
protected IStatus run(IProgressMonitor monitor) {
- String encoding = getEncoding();
+ if (fInput == null) {
+ return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
+ }
+ Charset encoding = getCharset();
+ readingStream = fInput;
+ InputStreamReader streamReader = (encoding == null ? new InputStreamReader(readingStream)
+ : new InputStreamReader(readingStream, encoding));
try {
- byte[] b = new byte[1024];
- int read = 0;
- while (read >= 0 && !monitor.isCanceled()) {
- readingStream = fInput;
- if (readingStream == null) {
+ char[] cbuf = new char[1024];
+ int charRead = 0;
+ while (charRead >= 0 && !monitor.isCanceled()) {
+ if (fInput == null) {
break;
}
- read = readingStream.read(b);
- if (read > 0) {
- String s;
- if (encoding != null) {
- s = new String(b, 0, read, encoding);
- } else {
- s = new String(b, 0, read);
- }
+ if (fInput != readingStream) {
+ readingStream = fInput;
+ streamReader = (encoding == null ? new InputStreamReader(readingStream)
+ : new InputStreamReader(readingStream, encoding));
+ }
+
+ charRead = streamReader.read(cbuf);
+ if (charRead > 0) {
+ String s = new String(cbuf, 0, charRead);
streamsProxy.write(s);
}
}

Back to the top