primitive parseUtf8() implementation to ensure we handle null characters correctly, at least

This commit is contained in:
Joel Dice 2007-10-24 15:05:15 -06:00
parent c694b8c7e6
commit 2c2718fdb5

View File

@ -502,6 +502,41 @@ makeJNIName(Thread* t, object method, bool decorate)
return name; return name;
} }
object
parseUtf8(Thread* t, Stream& s, unsigned length)
{
object value = makeByteArray(t, length + 1, false);
unsigned vi = 0;
for (unsigned si = 0; si < length; ++ si, ++ vi) {
unsigned a = s.read1();
if (a & 0x80) {
++ si;
assert(t, si < length);
unsigned b = s.read1();
if (a == 0xC0 and b == 0x80) {
byteArrayBody(t, value, vi) = 0;
} else {
abort(t); // todo
}
} else {
byteArrayBody(t, value, vi) = a;
}
}
if (vi < length) {
PROTECT(t, value);
object v = makeByteArray(t, vi + 1, false);
memcpy(&byteArrayBody(t, v, 0), &byteArrayBody(t, value, 0), vi);
value = v;
}
byteArrayBody(t, value, vi) = 0;
return value;
}
object object
parsePool(Thread* t, Stream& s) parsePool(Thread* t, Stream& s)
{ {
@ -537,10 +572,7 @@ parsePool(Thread* t, Stream& s)
} break; } break;
case CONSTANT_Utf8: { case CONSTANT_Utf8: {
unsigned length = s.read2(); object value = parseUtf8(t, s, s.read2());
object value = makeByteArray(t, length + 1, false);
s.read(reinterpret_cast<uint8_t*>(&byteArrayBody(t, value, 0)), length);
byteArrayBody(t, value, length) = 0;
set(t, pool, ArrayBody + (i * BytesPerWord), value); set(t, pool, ArrayBody + (i * BytesPerWord), value);
} break; } break;