Skip to content

Serialization: Harden recovery from broken deserialization context #72561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,11 @@ ProtocolConformanceDeserializer::readInheritedProtocolConformance(
InheritedProtocolConformanceLayout::readRecord(scratch, conformanceID,
conformingTypeID);

Type conformingType = MF.getType(conformingTypeID);
auto conformingTypeOrError =
MF.getTypeChecked(conformingTypeID);
if (!conformingTypeOrError)
return conformingTypeOrError.takeError();
Type conformingType = conformingTypeOrError.get();

PrettyStackTraceType trace(ctx, "reading inherited conformance for",
conformingType);
Expand Down Expand Up @@ -3465,7 +3469,10 @@ class DeclDeserializer {
}
}

auto DC = MF.getDeclContext(contextID);
auto DCOrError = MF.getDeclContextChecked(contextID);
if (!DCOrError)
return DCOrError.takeError();
auto DC = DCOrError.get();
if (declOrOffset.isComplete())
return declOrOffset;

Expand Down Expand Up @@ -3806,14 +3813,22 @@ class DeclDeserializer {
AddAttribute(new (ctx) HasStorageAttr(/*isImplicit:*/true));

if (opaqueReturnTypeID) {
auto opaqueReturnType = MF.getDeclChecked(opaqueReturnTypeID);
if (!opaqueReturnType)
return opaqueReturnType.takeError();

ctx.evaluator.cacheOutput(
OpaqueResultTypeRequest{var},
cast<OpaqueTypeDecl>(MF.getDecl(opaqueReturnTypeID)));
cast<OpaqueTypeDecl>(opaqueReturnType.get()));
}

// If this is a lazy property, record its backing storage.
if (lazyStorageID) {
VarDecl *storage = cast<VarDecl>(MF.getDecl(lazyStorageID));
auto lazyStorageDecl = MF.getDeclChecked(lazyStorageID);
if (!lazyStorageDecl)
return lazyStorageDecl.takeError();

VarDecl *storage = cast<VarDecl>(lazyStorageDecl.get());
ctx.evaluator.cacheOutput(
LazyStoragePropertyRequest{var}, std::move(storage));
}
Expand Down