fix: reject malformed history snapshot text
This commit is contained in:
@@ -8,6 +8,10 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CodingErrorAction;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.net.URLClassLoader;
|
||||
@@ -82,7 +86,16 @@ public final class HistoricalQueueLoader {
|
||||
}
|
||||
|
||||
public static void verifySha256(String expected, byte[] bytes) {
|
||||
byte[] canonicalBytes = new String(bytes, StandardCharsets.UTF_8)
|
||||
CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder()
|
||||
.onMalformedInput(CodingErrorAction.REPORT)
|
||||
.onUnmappableCharacter(CodingErrorAction.REPORT);
|
||||
String text;
|
||||
try {
|
||||
text = decoder.decode(ByteBuffer.wrap(bytes)).toString();
|
||||
} catch (CharacterCodingException ex) {
|
||||
throw new IllegalArgumentException("history snapshot must be valid UTF-8", ex);
|
||||
}
|
||||
byte[] canonicalBytes = text
|
||||
.replace("\r\n", "\n")
|
||||
.replace('\r', '\n')
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -50,6 +49,7 @@ public final class HistoricalReplayReportWriter {
|
||||
}
|
||||
summary.put("vehicles", vehicles);
|
||||
summary.put("taskTypes", taskTypes);
|
||||
summary.put("dimensionScope", "REPRESENTATIVE_SAMPLE");
|
||||
summary.put("replayableRows", paths.stream().filter(HistoricalPath::isReplayable).count());
|
||||
summary.put("qualityIssueRows", paths.stream().filter(p -> !p.getIssues().isEmpty()).count());
|
||||
Map<String, Integer> issueCounts = new LinkedHashMap<String, Integer>();
|
||||
|
||||
Reference in New Issue
Block a user