Memory corruption in System.Move due to changed 8087CW mode (png + stretchblt)

后端 未结 4 986
孤城傲影
孤城傲影 2020-12-29 04:37

I have strange a memory corruption problem. After many hours debugging and trying I think I found something.

For example: I do a simple string assignment:

         


        
4条回答
  •  情深已故
    2020-12-29 04:51

    For those still interested in this: There's yet another possible cause of problems:

    Delphi Rio still ships with a broken ASM version of Move.

    I had the pleasure to run into that bug today, luckily enough I had a reproducible test case. The issue is this piece of code:

    * ***** BEGIN LICENSE BLOCK *****
     *
     * The assembly function Move is licensed under the CodeGear license terms.
     *
     * The initial developer of the original code is Fastcode
     *
     * Portions created by the initial developer are Copyright (C) 2002-2004
     * the initial developer. All Rights Reserved.
     *
     * Contributor(s): John O'Harrow
     *
     * ***** END LICENSE BLOCK ***** *)
    
    // ... some less interesting parts omitted ...
    
    @@LargeMove:
            JNG     @@LargeDone {Count < 0}
            CMP     EAX, EDX
            JA      @@LargeForwardMove
    
            // the following overlap test is broken
            // when size>uint(destaddr), EDX underflows to $FFxxxxxx, in which case 
            // we jump to @LargeForwardMove even if a backward loop would be appropriate
            // this will effectively shred everything at EDX + size
            SUB     EDX, ECX              // when this underflows ...
            CMP     EAX, EDX              // ... we also get CF=1 here (EDX is usually < $FFxxxxxx)
            LEA     EDX, [EDX+ECX]        // (does not affect flags)
            JNA     @@LargeForwardMove    // ... CF=1 so let's jump into disaster!
    
            SUB     ECX, 8 {Backward Move}
            PUSH    ECX
            FILD    QWORD PTR [EAX+ECX] {Last 8}
            FILD    QWORD PTR [EAX] {First 8}
            ADD     ECX, EDX
            AND     ECX, -8 {8-Byte Align Writes}
            SUB     ECX, EDX
    

    References

    • Intel EFLAGS Cross-Reference and Condition Codes
    • CMP operation
    • SUB operation

提交回复
热议问题