binpac: BIT-1829: fix &length suppressing boundary checks for array elements

It should only suppress the parsing-loop boundary check in the case
where array elaments are a single byte in length and thus covered by
the boundary check (generated as a result of &length) that is placed
before the parsing-loop.
This commit is contained in:
Jon Siwek 2018-05-18 09:13:17 -05:00 committed by Tim Wojtulewicz
parent 39547dccec
commit 9c61eefe0d

View file

@ -683,6 +683,17 @@ int ArrayType::StaticSize(Env *env) const
void ArrayType::SetBoundaryChecked() void ArrayType::SetBoundaryChecked()
{ {
Type::SetBoundaryChecked(); Type::SetBoundaryChecked();
if ( attr_length_expr_ )
{
// When using &length on an array, only treat its elements as
// already-bounds-checked if they are a single byte in length.
if ( elemtype_->StaticSize(env()) == 1 )
elemtype_->SetBoundaryChecked();
return;
}
elemtype_->SetBoundaryChecked(); elemtype_->SetBoundaryChecked();
} }