Remove four useless checks in dlls/gdi32/enhmetafile.c (RESEND)

Gerald Pfeifer gerald at pfeifer.com
Sun Dec 2 15:28:30 CST 2007


On Mon, 19 Nov 2007, Alexandre Julliard wrote:
>> I had expected this comment for a different patch of mine.  In 
>> dlls/gdi32/enhmetafile.c we are just reading existing records,
>> so I'm not sure what you have in mind here?
> The records usually come from an external file, so they have to be
> validated (not that this is done correctly everywhere, but we should
> move towards more validation, not less).

I've been looking into this, and I'm afraid I'll need some help to 
proceed.  If you look at the code and my original patch below, you
will see that I removed four conditions which were noops, that is,
the compiler should (and could) simply remove them.

This is what my patch did at the source level.

If we want to add some input checking, I assume you would like to 
check that these values are not too large?  (They cannot be negative,
so the only range checking we can do is on the upper end.)  How should
this look like?  Any specific upper bounds you have in mind?

Or did I simply fail to explain my original patch, that is, convey the
point that this actually will not change program behavior?

Gerald

Index: dlls/gdi32/enhmetafile.c
===================================================================
RCS file: /home/wine/wine/dlls/gdi32/enhmetafile.c,v
retrieving revision 1.6
diff -u -3 -p -r1.6 enhmetafile.c
--- dlls/gdi32/enhmetafile.c	3 Aug 2007 13:06:43 -0000	1.6
+++ dlls/gdi32/enhmetafile.c	28 Nov 2007 23:18:34 -0000
@@ -1670,9 +1670,7 @@ BOOL WINAPI PlayEnhMetaFileRecord(
         LPVOID lpPackedStruct;
 
         /* check that offsets and data are contained within the record */
-        if ( !( (lpCreate->cbBmi>=0) && (lpCreate->cbBits>=0) &&
-                (lpCreate->offBmi>=0) && (lpCreate->offBits>=0) &&
-                ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
+        if ( !( ((lpCreate->offBmi +lpCreate->cbBmi ) <= mr->nSize) &&
                 ((lpCreate->offBits+lpCreate->cbBits) <= mr->nSize) ) )
         {
             ERR("Invalid EMR_CREATEDIBPATTERNBRUSHPT record\n");



More information about the wine-devel mailing list