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:
Jakob Buchgraber 2016-06-30 16:28:45 +02:00 committed by GitHub
parent f149e4c175
commit c5733742ce
1 changed files with 3 additions and 2 deletions

View File

@ -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);