// Record state at beginning of section to allow rewinding to this point // if, after skipping through several custom sections, we don't find the // section 'id'. const uint8_t* const initialCur = cur_; const size_t initialCustomSectionsLength =
codeMeta->customSectionRanges.length();
// Maintain a pointer to the current section that gets updated as custom // sections are skipped. const uint8_t* currentSectionStart = cur_;
// Only start a section with 'id', skipping any custom sections before it.
uint8_t idValue; if (!readFixedU8(&idValue)) { goto rewind;
}
while (idValue != uint8_t(id)) { if (idValue != uint8_t(SectionId::Custom)) { goto rewind;
}
// Rewind to the beginning of the current section since this is what // skipCustomSection() assumes.
cur_ = currentSectionStart; if (!skipCustomSection(codeMeta)) { returnfalse;
}
// Having successfully skipped a custom section, consider the next // section.
currentSectionStart = cur_; if (!readFixedU8(&idValue)) { goto rewind;
}
}
// Don't check the size since the range of bytes being decoded might not // contain the section body. (This is currently the case when streaming: the // code section header is decoded with the module environment bytes, the // body of the code section is streamed in separately.)
uint32_t size; if (!readVarU32(&size)) { goto fail;
}
range->emplace(); if (!BytecodeRange::fromStartAndSize(currentOffset(), size, range->ptr())) { goto fail;
} returntrue;
bool Decoder::startCustomSection(constchar* expected, size_t expectedLength,
CodeMetadata* codeMeta,
MaybeBytecodeRange* range) { // Record state at beginning of section to allow rewinding to this point // if, after skipping through several custom sections, we don't find the // section 'id'. const uint8_t* const initialCur = cur_; const size_t initialCustomSectionsLength =
codeMeta->customSectionRanges.length();
while (true) { // Try to start a custom section. If we can't, rewind to the beginning // since we may have skipped several custom sections already looking for // 'expected'. if (!startSection(SectionId::Custom, codeMeta, range, "custom")) { returnfalse;
} if (!*range) { goto rewind;
}
if (bytesRemain() < (*range)->size()) { goto fail;
}
// A custom section name must be valid UTF-8 if (!IsUtf8(AsChars(mozilla::Span(cur_, sectionNameSize)))) { goto fail;
}
CustomSectionRange secRange;
secRange.name = BytecodeRange(currentOffset(), sectionNameSize); // The payload starts after the name, and goes to the end of the custom // section. if (secRange.name.end > (*range)->end) { goto fail;
}
secRange.payload.start = secRange.name.end;
secRange.payload.end = (*range)->end;
// Now that we have a valid custom section, record its offsets in the // metadata which can be queried by the user via Module.customSections. // Note: after an entry is appended, it may be popped if this loop or // the loop in startSection needs to rewind. if (!codeMeta->customSectionRanges.append(secRange)) { returnfalse;
}
// If this is the expected custom section, we're done. if (!expected || (expectedLength == secRange.name.size() &&
!memcmp(cur_, expected, secRange.name.size()))) {
cur_ += secRange.name.size(); returntrue;
}
// Otherwise, blindly skip the custom section and keep looking.
skipAndFinishCustomSection(**range);
range->reset();
}
MOZ_CRASH("unreachable");
bool Decoder::finishNameSubsection(uint32_t endOffset) {
uint32_t actual = currentOffset(); if (endOffset != actual) { return failf("bad name subsection length (endOffset: %" PRIu32 ", actual: %" PRIu32 ")",
endOffset, actual);
}
returntrue;
}
bool Decoder::skipNameSubsection() {
uint8_t nameTypeValue; if (!readFixedU8(&nameTypeValue)) { return fail("unable to read name subsection id");
}
switch (nameTypeValue) { case uint8_t(NameType::Module): case uint8_t(NameType::Function): return fail("out of order name subsections"); default: break;
}
uint32_t payloadLength; if (!readVarU32(&payloadLength) || !readBytes(payloadLength)) { return fail("bad name subsection payload length");
}
returntrue;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.