Skip to content

Commit

Permalink
Changed DataInput to use readByte so EOF is thrown.
Browse files Browse the repository at this point in the history
Otherwise an unexpected int or invalid string can be read.
  • Loading branch information
NathanSweet committed Feb 21, 2023
1 parent 0459aa6 commit eaefce3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions gdx/src/com/badlogic/gdx/utils/DataInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public DataInput (InputStream in) {

/** Reads a 1-5 byte int. */
public int readInt (boolean optimizePositive) throws IOException {
int b = read();
int b = readByte();
int result = b & 0x7F;
if ((b & 0x80) != 0) {
b = read();
b = readByte();
result |= (b & 0x7F) << 7;
if ((b & 0x80) != 0) {
b = read();
b = readByte();
result |= (b & 0x7F) << 14;
if ((b & 0x80) != 0) {
b = read();
b = readByte();
result |= (b & 0x7F) << 21;
if ((b & 0x80) != 0) {
b = read();
b = readByte();
result |= (b & 0x7F) << 28;
}
}
Expand All @@ -69,7 +69,7 @@ public int readInt (boolean optimizePositive) throws IOException {
int charIndex = 0;
int b = 0;
while (charIndex < charCount) {
b = read();
b = readByte();
if (b > 127) break;
chars[charIndex++] = (char)b;
}
Expand All @@ -94,14 +94,14 @@ private void readUtf8_slow (int charCount, int charIndex, int b) throws IOExcept
break;
case 12:
case 13:
chars[charIndex] = (char)((b & 0x1F) << 6 | read() & 0x3F);
chars[charIndex] = (char)((b & 0x1F) << 6 | readByte() & 0x3F);
break;
case 14:
chars[charIndex] = (char)((b & 0x0F) << 12 | (read() & 0x3F) << 6 | read() & 0x3F);
chars[charIndex] = (char)((b & 0x0F) << 12 | (readByte() & 0x3F) << 6 | readByte() & 0x3F);
break;
}
if (++charIndex >= charCount) break;
b = read() & 0xFF;
b = readByte() & 0xFF;
}
}
}

0 comments on commit eaefce3

Please sign in to comment.