On Wed, Jul 8, 2009 at 1:56 PM, Vin Shelton <ethersoft@gmail.com> wrote:
Hi, Jerry -

On Wed, Jul 1, 2009 at 6:42 PM, Jerry
James<jjames-guest@alioth.debian.org> wrote:
> changeset:   4646:6c6bfdb80a0c
> tag:         tip
> user:        Jerry James <james@xemacs.org>
> date:        Wed Jul 01 16:42:11 2009 -0600
> files:       src/ChangeLog src/glyphs-eimage.c
> description:
> Prevent integer overflow and subsequent crashes when attempting to load large
> images.  See <870180fe0907011540m7509f371h97d336477145166a@mail.gmail.com> in
> xemacs-patches.

Thank you for the patch.  I finally got around to trying to build this
on Windows and ran into a problem - Visual Studio 6.0 (a little
ancient, but still quite serviceable) doesn't support "long long" so I
get the following errors:

C:\cygwin\usr\local\src\xemacs-21.5-test-2009-07-08\src\glyphs-eimage.c(412)
: error C2065: 'UINT_64_BIT' : undeclared identifier
C:\cygwin\usr\local\src\xemacs-21.5-test-2009-07-08\src\glyphs-eimage.c(412)
: error C2146: syntax error : missing ';' before identifier
'pixels_sq'
...
and so on
....

so I generated the following patch:

diff -r -u --exclude=.hg xemacs-bleeding-edge-pristine/src/lisp.h
xemacs-21.5-jerry/src/lisp.h
--- xemacs-bleeding-edge-pristine/src/lisp.h    2009-06-22
22:44:53.250000000 -0400
+++ xemacs-21.5-jerry/src/lisp.h        2009-07-08 13:26:44.421875000 -0400
@@ -211,6 +211,9 @@
 #define UINT_64_BIT unsigned long long
 #define MAKE_64_BIT_UNSIGNED_CONSTANT(num) num##ULL
 /* No error otherwise; just leave undefined */
+#elif SIZEOF_LONG_LONG == 0
+#define INT_64_BIT __int64
+#define UINT_64_BIT unsigned __int64
 #endif

 #if SIZEOF_LONG_LONG == 16
@@ -221,7 +224,7 @@
 #endif

 /* #### Fill this in for other systems */
-#if defined (INT_64_BIT) && !(defined (i386) || defined (__i386__))
+#if defined (INT_64_BIT) && !(defined (i386) || defined (__i386__) ||
SIZEOF_LONG_LONG == 0)
 #define EFFICIENT_INT_64_BIT INT_64_BIT
 #define EFFICIENT_UINT_64_BIT UINT_64_BIT
 #endif

That solved the compile error, but generated the following warning
when compiling glyphs-eimage.c:
C:\cygwin\usr\local\src\xemacs-21.5-test-2009-07-08\src\glyphs-eimage.c(1340)
: warning C4244: 'argument' : conversion from 'unsigned __int64' to
'long', possible loss of data

That warning apparently comes from the xnew_binbyte(), which
ultimately translates into an xmalloc() call.  What do you think - do
you have any suggestions for cleaning up this warning, or should I not
worry about it, or what?

Regards,
 Vin

Sorry to take so long.  I'm actually on vacation, and have only sporadic access to email, and pretty much no access to any machine capable of actual development activities.  This will continue for another week.  I see I have a bunch of other emails I need to reply to.  Sorry, everyone, I'll get to them Real Soon Now.

I guess that 'long' is a 32-bit quantity in this environment?  Does the system malloc take a long, or something else?

I think this warning does need to be worried about.  It indicates that the compiler is generating code that will let us overflow a buffer, exactly the problem we're trying to get rid of.  Of course, this would only be the case with buffers greater than 4 GB.  If necessary, we can make that the cutoff point for Visual Studio.
--
Jerry James
http://www.jamezone.org/