mirror of https://github.com/grpc/grpc-java.git
netty: fix incorrect usage of AsciString.
An AsciiString object may only use a subsection of its backing byte array. We need to test for this and return a copy of the subsection if necessary. Big thanks to @normanmaurer for uncovering this issue: https://github.com/netty/netty/issues/5472
This commit is contained in:
parent
f149e4c175
commit
c5733742ce
|
|
@ -106,8 +106,9 @@ class Utils {
|
|||
|
||||
private static byte[] bytes(CharSequence seq) {
|
||||
if (seq instanceof AsciiString) {
|
||||
// Fast path - no copy.
|
||||
return ((AsciiString) seq).array();
|
||||
// Fast path - sometimes copy.
|
||||
AsciiString str = (AsciiString) seq;
|
||||
return str.isEntireArrayUsed() ? str.array() : str.toByteArray();
|
||||
}
|
||||
// Slow path - copy.
|
||||
return seq.toString().getBytes(UTF_8);
|
||||
|
|
|
|||
Loading…
Reference in New Issue