Skip to content

VM: Function::KernelLibraryIndex() can return -1, causing KernelProgramInfo::KernelLibrary to be asked for the typed data for library -1 #60369

@jensjoha

Description

@jensjoha

sdk/runtime/vm/object.cc

Lines 11424 to 11429 in 05fc6bd

intptr_t Function::KernelLibraryIndex() const {
ASSERT(!is_declared_in_bytecode());
if (IsNoSuchMethodDispatcher() || IsInvokeFieldDispatcher() ||
IsFfiCallbackTrampoline()) {
return -1;
}

sdk/runtime/vm/object.cc

Lines 15695 to 15701 in 05fc6bd

TypedDataViewPtr KernelProgramInfo::KernelLibrary(
intptr_t library_index) const {
const intptr_t start_offset = KernelLibraryStartOffset(library_index);
const intptr_t end_offset = KernelLibraryEndOffset(library_index);
const auto& component = TypedDataBase::Handle(kernel_component());
return component.ViewFromTo(start_offset, end_offset);
}

This used "to work" because when reading the start and end offsets for the library, the read end was the start of library 0 and the read start was the nnbd component mode (a number between 0 and 4 I think). It then created a view from, say 0 to where-ever-lib-1-starts (and the data is then (hopefully) never really read (I think it only logically checks that the size is > 0)).
When removing the nnbd component mode it instead reads the "mainMethodReference" which is a semi-arbitrary number which can be larger than where-ever library 0 starts, the start can thus become larger than the end and debug builds become sad: https://dart-ci.firebaseapp.com/cl/416940/1

I'm adding some special handling in https://dart-review.googlesource.com/c/sdk/+/416940 but it should probably be fixed better so it never requests data for library -1.

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions