aws / lumberyard

Amazon Lumberyard is a free AAA game engine deeply integrated with AWS and Twitch – with full source.
Other
2.03k stars 540 forks source link

Always call IDataConverter::ConvertToType in ObjectStreamImpl::GetElementStorageAddress #424

Open yuriy0 opened 5 years ago

yuriy0 commented 5 years ago

Issue #, if available:

Description of changes: The implementation of serialization of AZStd::variant relies on storing the alternative data on serialization via ObjectStreamWriteElementOverride attribute; then on deserialization it relies on VariantDataConverter::ConvertFromType being called to offset a pointer to AZStd::variant<T1, .., Tn> to a pointer to Ti if the serialized value is Ti.

The problem is this function is not called for non-pointer datums by ObjectStream. This results in a pointer to a AZStd::variant<T1, .., Tn> being reinterpreted as a pointer to Ti - at worst this causes a segfault so it’s a pretty severe issue. In theory this might work for some implementations of variant and for some platform, but it’s clear that:

This merge request changes ObjectStreamImpl::GetElementStorageAddress to always call ConvertFromType if CanConvertFromType returns true.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

sconel commented 5 years ago

Hi @yuriy0, thanks for contributing to LY we'll take a look at the change.