Skip to content

Commit 6649cc3

Browse files
committed
Fix issues found by Coverity
Throw an exception if the file stream is shorter than expected. Make inner result class static.
1 parent a08f7c5 commit 6649cc3

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/main/java/com/maxmind/db/BufferHolder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ final class BufferHolder {
2222
final FileChannel channel = file.getChannel();
2323
if (mode == FileMode.MEMORY) {
2424
this.buffer = ByteBuffer.wrap(new byte[(int) channel.size()]);
25-
channel.read(this.buffer);
25+
if (channel.read(this.buffer) != this.buffer.capacity()) {
26+
throw new IOException("Unable to read "
27+
+ database.getName()
28+
+ " into memory. Unexpected end of stream.");
29+
}
2630
} else {
2731
this.buffer = channel.map(MapMode.READ_ONLY, 0, channel.size());
2832
}

src/main/java/com/maxmind/db/Decoder.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@
77

88
import com.fasterxml.jackson.databind.JsonNode;
99
import com.fasterxml.jackson.databind.ObjectMapper;
10-
import com.fasterxml.jackson.databind.node.ArrayNode;
11-
import com.fasterxml.jackson.databind.node.BigIntegerNode;
12-
import com.fasterxml.jackson.databind.node.BinaryNode;
13-
import com.fasterxml.jackson.databind.node.BooleanNode;
14-
import com.fasterxml.jackson.databind.node.DoubleNode;
15-
import com.fasterxml.jackson.databind.node.FloatNode;
16-
import com.fasterxml.jackson.databind.node.IntNode;
17-
import com.fasterxml.jackson.databind.node.LongNode;
18-
import com.fasterxml.jackson.databind.node.ObjectNode;
19-
import com.fasterxml.jackson.databind.node.TextNode;
10+
import com.fasterxml.jackson.databind.node.*;
2011

2112
/*
2213
* Decoder for MaxMind DB data.
@@ -55,7 +46,7 @@ public static Type fromControlByte(int b) {
5546
}
5647
}
5748

58-
class Result {
49+
static class Result {
5950
private final JsonNode node;
6051
private int offset;
6152

0 commit comments

Comments
 (0)