diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2013-04-14 19:15:53 +0200 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2013-04-14 19:53:48 +0200 |
commit | 4c638be79fde7c34ca0fcaad13d7c4f1d9c5ddd2 (patch) | |
tree | a07f7436c61292b23b25671edfbbbaed71aeaa00 /org.eclipse.jgit | |
parent | a6ed390ea79ad0a29265448a1c294e9a1953eb53 (diff) | |
download | jgit-4c638be79fde7c34ca0fcaad13d7c4f1d9c5ddd2.tar.gz jgit-4c638be79fde7c34ca0fcaad13d7c4f1d9c5ddd2.zip |
Fix boundary conditions in AutoCRLFOutputStream
This fixes some problems with inputs around the size of the internal
buffer in AutoCRLFOutputStream (8000).
Tests supplied by Robin Stocker.
Bug: 405672
Change-Id: I6147897290392b3bfd4040e8006da39c302a3d49
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java index fe073d83b1..1ce277439c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, Robin Rosenberg + * Copyright (C) 2011, 2013 Robin Rosenberg * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -55,11 +55,15 @@ import org.eclipse.jgit.diff.RawText; */ public class AutoCRLFOutputStream extends OutputStream { + static final int BUFFER_SIZE = 8000; + private final OutputStream out; private int buf = -1; - private byte[] binbuf = new byte[8000]; + private byte[] binbuf = new byte[BUFFER_SIZE]; + + private byte[] onebytebuf = new byte[1]; private int binbufcnt = 0; @@ -74,29 +78,8 @@ public class AutoCRLFOutputStream extends OutputStream { @Override public void write(int b) throws IOException { - int overflow = buffer((byte) b); - if (overflow >= 0) - return; - if (isBinary) { - out.write(b); - return; - } - if (b == '\n') { - if (buf == '\r') { - out.write('\n'); - buf = -1; - } else if (buf == -1) { - out.write('\r'); - out.write('\n'); - buf = -1; - } - } else if (b == '\r') { - out.write(b); - buf = '\r'; - } else { - out.write(b); - buf = -1; - } + onebytebuf[0] = (byte) b; + write(onebytebuf, 0, 1); } @Override @@ -144,15 +127,6 @@ public class AutoCRLFOutputStream extends OutputStream { buf = '\r'; } - private int buffer(byte b) throws IOException { - if (binbufcnt > binbuf.length) - return 1; - binbuf[binbufcnt++] = b; - if (binbufcnt == binbuf.length) - decideMode(); - return 0; - } - private int buffer(byte[] b, int off, int len) throws IOException { if (binbufcnt > binbuf.length) return len; @@ -174,7 +148,7 @@ public class AutoCRLFOutputStream extends OutputStream { @Override public void flush() throws IOException { - if (binbufcnt < binbuf.length) + if (binbufcnt <= binbuf.length) decideMode(); buf = -1; out.flush(); |