Skip to content

Commit dd7e67c

Browse files
committed
handle corrupted replays
1 parent 726a59d commit dd7e67c

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

pom.xml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,8 @@
2424
<id>jitpack.io</id>
2525
<url>https://jitpack.io</url>
2626
</repository>
27-
<repository>
28-
<id>sonatype.oss.snapshots</id>
29-
<name>Sonatype OSS Snapshot Repository</name>
30-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
31-
<releases>
32-
<enabled>false</enabled>
33-
</releases>
34-
<snapshots>
35-
<enabled>true</enabled>
36-
</snapshots>
37-
</repository>
3827
</repositories>
3928
<dependencies>
40-
<!--
41-
<dependency>
42-
<groupId>com.github.skadistats</groupId>
43-
<artifactId>clarity</artifactId>
44-
<version>master-SNAPSHOT</version>
45-
</dependency>
46-
-->
4729
<!--
4830
<dependency>
4931
<groupId>com.github.skadistats</groupId>
@@ -62,16 +44,22 @@
6244
<artifactId>gson</artifactId>
6345
<version>2.8.9</version>
6446
</dependency>
47+
48+
<dependency>
49+
<groupId>org.apache.commons</groupId>
50+
<artifactId>commons-compress</artifactId>
51+
<version>1.28.0</version>
52+
</dependency>
6553
</dependencies>
66-
<dependencyManagement>
54+
<!-- <dependencyManagement>
6755
<dependencies>
6856
<dependency>
6957
<groupId>com.skadistats</groupId>
7058
<artifactId>clarity-protobuf</artifactId>
7159
<version>5.4</version>
7260
</dependency>
7361
</dependencies>
74-
</dependencyManagement>
62+
</dependencyManagement> -->
7563
<build>
7664
<plugins>
7765
<plugin>

scripts/test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ curl localhost:5600 --data-binary "@/home/howardc/parser/8583844960_1679394786.d
44

55
curl localhost:5600/blob?replay_url=http://replay271.valve.net/570/8623065989_1426557301.dem.bz2
66
curl localhost:5600/blob?replay_url=http://www.example.com
7-
curl localhost:5600/blob?replay_url=https://odota.github.io/testfiles/1781962623_1.dem
7+
curl localhost:5600/blob?replay_url=https://odota.github.io/testfiles/1781962623_1.dem
8+
curl localhost:5600/blob?replay_url=http://replay113.valve.net/570/2562582896_1605238528.dem.bz2

src/main/java/opendota/Main.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,42 @@ public void handle(HttpExchange t) throws IOException {
9393
if (replayUrl.toString().endsWith(".bz2")) {
9494
tStart = System.currentTimeMillis();
9595
// Write byte[] to bunzip, get back decompressed byte[]
96+
// The C decompressor is a bit faster than Java, 4.3 vs 4.8s
97+
// BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new ByteArrayInputStream(bzIn));
98+
// bzOut = bz.readAllBytes();
99+
// bz.close();
100+
96101
Process bz = new ProcessBuilder(new String[] { "bunzip2" }).start();
97102
// Start separate thread so we can consume output while sending input
98-
Thread thread = new Thread(() -> {
103+
new Thread(() -> {
99104
try {
100105
bz.getOutputStream().write(bzIn);
101106
bz.getOutputStream().close();
102107
} catch (IOException ex) {
103108
ex.printStackTrace();
104109
}
105-
});
106-
thread.start();
110+
}).start();
107111

108112
bzOut = bz.getInputStream().readAllBytes();
113+
bz.getInputStream().close();
109114
String bzError = new String(bz.getErrorStream().readAllBytes());
115+
bz.getErrorStream().close();
110116
System.err.println(bzError);
117+
if (bzError.toString().contains("bunzip2: Data integrity error when decompressing") || bzError.contains("bunzip2: Compressed file ends unexpectedly")) {
118+
// Corrupted replay, don't retry
119+
t.sendResponseHeaders(200, 0);
120+
t.getResponseBody().close();
121+
return;
122+
}
111123
tEnd = System.currentTimeMillis();
112124
System.err.format("bunzip2: %dms\n", tEnd - tStart);
113125
}
114126

115127
// Start parser with input stream created from byte[]
116128
tStart = System.currentTimeMillis();
117-
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
118-
new Parse(new ByteArrayInputStream(bzOut), baos2, true);
119-
byte[] parseOut = baos2.toByteArray();
129+
ByteArrayOutputStream parseOutStream = new ByteArrayOutputStream();
130+
new Parse(new ByteArrayInputStream(bzOut), parseOutStream, true);
131+
byte[] parseOut = parseOutStream.toByteArray();
120132
tEnd = System.currentTimeMillis();
121133
System.err.format("parse: %dms\n", tEnd - tStart);
122134

0 commit comments

Comments
 (0)