www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20793] New: Variant equals of different types

https://issues.dlang.org/show_bug.cgi?id=20793

          Issue ID: 20793
           Summary: Variant equals of different types
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: mrsmith33 yandex.ru

Code to reproduce:
---
struct S1 {
        ubyte a;
        ubyte[64] u;
}
struct S2 {
        ubyte a;
        ubyte[64] u;
}
void main(){
        import std.variant, std.stdio;
        Variant var1 = Variant(S1(1));
        Variant var2 = Variant(const S1(2));
        writefln("%s", var1 == var2);
}
---
Problem is in these lines
https://github.com/dlang/phobos/blob/22055634e4b455135cebb65a2d562f21472c1e88/std/variant.d#L416-L418

Address to temp.store is passed to tryPutting, which expects address to memory
of A.sizeof. So, tryPutting writes A.sizeof bytes into &temp.store corrupting
the stack.

--
May 02 2020