mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-03-05 23:20:32 +07:00
Fixed bug reading string where null characters were included within content
This commit is contained in:
parent
7667cfdff2
commit
3c56558e9c
@ -495,9 +495,9 @@ public class BitInput {
|
||||
final byte[] dst = new byte[maxLen];
|
||||
for (int i = 0; i < maxLen; i++) {
|
||||
final byte b = dst[i] = (byte) readUnsigned(bits);
|
||||
if (nullTerminated && b == '\0') break;
|
||||
if (nullTerminated && b == '\0') maxLen = i;
|
||||
}
|
||||
|
||||
return new String(dst);
|
||||
return new String(dst, 0, maxLen);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.riiablo.util.DebugUtils;
|
||||
|
||||
@ -487,7 +488,9 @@ public class ByteInput {
|
||||
assert aligned() : "not aligned";
|
||||
try {
|
||||
incrementBitsRead((long) len * Byte.SIZE);
|
||||
return buffer.readCharSequence(len, CharsetUtil.US_ASCII).toString();
|
||||
CharSequence charSequence = buffer.readCharSequence(len, CharsetUtil.US_ASCII);
|
||||
charSequence = charSequence.subSequence(0, StringUtils.indexOf(charSequence, '\0'));
|
||||
return charSequence.toString();
|
||||
} catch (IndexOutOfBoundsException t) {
|
||||
throw new EndOfInput(t);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user