Skip to content

Make a temporary existential when reflecting weak properties #4397

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 1 commit into from
Aug 20, 2016
Merged

Make a temporary existential when reflecting weak properties #4397

merged 1 commit into from
Aug 20, 2016

Conversation

bitjammer
Copy link
Contributor

When getting a mirror child that is a class existential, there
may be witness tables for the protocol composition to copy. Don't
just take the address of a class instance pointer from the stack -
make a temporary existential-like before calling into the Mirror
constructor.

This now correctly covers reflecting weak optional class types, and weak
optional class existential types, along with fixing a stack buffer
overflow reported by the Address Sanitizer (thanks, ASan!).

Tests were also updated to check for the validity of the child's data.

rdar://problem/27348445

@bitjammer
Copy link
Contributor Author

@swift-ci Please test.

@bitjammer
Copy link
Contributor Author

@rjmccall Can you review?


// First create a temporary existential.
auto valueSize = type->getValueWitnesses()->getSize();
auto temporaryValue = static_cast<void*>(malloc(valueSize));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably more efficient to use vw_allocBuffer here.

When getting a mirror child that is a class existential, there
may be witness tables for the protocol composition to copy. Don't
just take the address of a class instance pointer from the stack -
make a temporary existential-like before calling into the Mirror
constructor.

This now correctly covers reflecting weak optional class types, and weak
optional class existential types, along with fixing a stack buffer
overflow reported by the Address Sanitizer (thanks, ASan!).

Tests were also updated to check for the validity of the child's data.

rdar://problem/27348445
@bitjammer
Copy link
Contributor Author

@swift-ci Please test.

@bitjammer
Copy link
Contributor Author

@swift-ci Please test OS X Platform.

@bitjammer
Copy link
Contributor Author

@swift-ci Smoke test OS X Platform.

@bitjammer
Copy link
Contributor Author

Smoke test didn't respond, but the full OS X platform test passed, so I'll merge.

@bitjammer bitjammer merged commit 985e32b into swiftlang:master Aug 20, 2016
@bitjammer bitjammer deleted the stack-overflow-class-existential-mirror-27348445 branch August 20, 2016 01:00
@@ -2337,11 +2339,15 @@ struct ClassExistentialContainer {
return reinterpret_cast<const WitnessTable* const *>(this + 1);
}

void copyTypeInto(ClassExistentialContainer *dest, unsigned numTables) const {
void copyTypeInto(ClassExistentialContainerImpl *dest,
unsigned numTables) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor request (totally unnecessary for 3.0): you could make this templated over the dest's value type, since it doesn't touch that field at all.

@rjmccall
Copy link
Contributor

LGTM, thanks!

@bitjammer
Copy link
Contributor Author

Thanks John!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants