From f2e64cd895a6aa4f18ab3b876f13b7814fb98f04 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 17 Oct 2017 15:17:34 +0200 Subject: Throw BinaryBlobException from RawParseUtils#lineMap. This makes detection of binaries exact for ResolveMerger and DiffFormatter: they will classify files as binary regardless of where the '\0' occurs in the text. Signed-off-by: Han-Wen Nienhuys Change-Id: Id4342a199628d9406bfa04af1b023c27a47d4014 --- .../src/org/eclipse/jgit/util/RawParseUtils.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java index ad138bbf18..0d6a8d9612 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java @@ -63,6 +63,7 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.jgit.annotations.Nullable; +import org.eclipse.jgit.errors.BinaryBlobException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.PersonIdent; @@ -618,9 +619,6 @@ public final class RawParseUtils { *

* The last element (index map.size()-1) always contains * end. - *

- * If the data contains a '\0' anywhere, the whole region is considered binary - * and a LineMap corresponding to a single line is returned. *

* * @param buf @@ -631,10 +629,9 @@ public final class RawParseUtils { * @param end * 1 past the end of the content within buf. * @return a line map indexing the start position of each line. + * @throws BinaryBlobException if any '\0' is found. */ - public static final IntList lineMap(final byte[] buf, int ptr, int end) { - int start = ptr; - + public static final IntList lineMap(final byte[] buf, int ptr, int end) throws BinaryBlobException { // Experimentally derived from multiple source repositories // the average number of bytes/line is 36. Its a rough guess // to initially size our map close to the target. @@ -647,11 +644,7 @@ public final class RawParseUtils { } if (buf[ptr] == '\0') { - // binary data. - map = new IntList(3); - map.add(Integer.MIN_VALUE); - map.add(start); - break; + throw new BinaryBlobException(); } foundLF = (buf[ptr] == '\n'); -- cgit v1.2.3