Skip to content

Commit

Permalink
2007-06-05 Sebastien Pouliot <sebastien@ximian.com>
Browse files Browse the repository at this point in the history
	* emfcodec.c, metafile-private.h, wmfcodec.c, wmfcodec.h: ++ is unsafe
	to use with the GUINTx_FROM_LE macro. Also avoid macro re-declarations


svn path=/trunk/libgdiplus/; revision=78678
  • Loading branch information
Sebastien Pouliot committed Jun 5, 2007
1 parent a89f39b commit 4133fea
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 35 deletions.
5 changes: 5 additions & 0 deletions src/ChangeLog
@@ -1,3 +1,8 @@
2007-06-05 Sebastien Pouliot <sebastien@ximian.com>

* emfcodec.c, metafile-private.h, wmfcodec.c, wmfcodec.h: ++ is unsafe
to use with the GUINTx_FROM_LE macro. Also avoid macro re-declarations

2007-05-30 Sebastien Pouliot <sebastien@ximian.com>

* gifcodec.c: Add support for interlaced GIF. Fix bug #81773
Expand Down
78 changes: 52 additions & 26 deletions src/emfcodec.c
Expand Up @@ -112,13 +112,18 @@ PolyBezier (MetafilePlayContext *context, BYTE *data, int len, BOOL compact)
GpStatus status;
int p, n = 0;
RECTL bounds;
bounds.left = GETDW(DWP(n++));
bounds.top = GETDW(DWP(n++));
bounds.right = GETDW(DWP(n++));
bounds.bottom = GETDW(DWP(n++));
bounds.left = GETDW(DWP(n));
n++;
bounds.top = GETDW(DWP(n));
n++;
bounds.right = GETDW(DWP(n));
n++;
bounds.bottom = GETDW(DWP(n));
n++;

/* make sure we're not reading more data than what's available in this record */
num = GETDW(DWP(n++));
num = GETDW(DWP(n));
n++;
if (compact) {
/* len = bounds (4 * DWORD) + num (DWORD) + 2 * num * (x WORD + y WORD) */
if (num > ((len - 5 * sizeof (DWORD)) >> 2))
Expand Down Expand Up @@ -150,12 +155,15 @@ PolyBezier (MetafilePlayContext *context, BYTE *data, int len, BOOL compact)
pt++;
for (p = 0; p < num; p++, pt++) {
if (compact) {
DWORD xy = GETDW(DWP(n++));
DWORD xy = GETDW(DWP(n));
n++;
pt->X = (xy & 0x0000FFFF);
pt->Y = (xy >> 16);
} else {
pt->X = GETDW(DWP(n++));
pt->Y = GETDW(DWP(n++));
pt->X = GETDW(DWP(n));
n++;
pt->Y = GETDW(DWP(n));
n++;
}
#ifdef DEBUG_EMF_2
printf ("\n\tbezier to %g,%g", pt->X, pt->Y);
Expand All @@ -182,13 +190,18 @@ Polygon (MetafilePlayContext *context, BYTE *data, int len, BOOL compact)
GpStatus status;
int p, n = 0;
RECTL bounds;
bounds.left = GETDW(DWP(n++));
bounds.top = GETDW(DWP(n++));
bounds.right = GETDW(DWP(n++));
bounds.bottom = GETDW(DWP(n++));
bounds.left = GETDW(DWP(n));
n++;
bounds.top = GETDW(DWP(n));
n++;
bounds.right = GETDW(DWP(n));
n++;
bounds.bottom = GETDW(DWP(n));
n++;

/* make sure we're not reading more data than what's available in this record */
num = GETDW(DWP(n++));
num = GETDW(DWP(n));
n++;
if (compact) {
/* len = bounds (4 * DWORD) + num (DWORD) + 2 * num * (x WORD + y WORD) */
if (num > ((len - 5 * sizeof (DWORD)) >> 2))
Expand All @@ -210,12 +223,15 @@ Polygon (MetafilePlayContext *context, BYTE *data, int len, BOOL compact)

for (p = 0, pt = points; p < num; p++, pt++) {
if (compact) {
DWORD xy = GETDW(DWP(n++));
DWORD xy = GETDW(DWP(n));
n++;
pt->X = (xy & 0x0000FFFF);
pt->Y = (xy >> 16);
} else {
pt->X = GETDW(DWP(n++));
pt->Y = GETDW(DWP(n++));
pt->X = GETDW(DWP(n));
n++;
pt->Y = GETDW(DWP(n));
n++;
}
#ifdef DEBUG_EMF_2
printf ("\n\tpoly to %g,%g", pt->X, pt->Y);
Expand All @@ -236,16 +252,22 @@ PolyPolygon (MetafilePlayContext *context, BYTE *data, BOOL compact)
int poly_num;
int n = 0;
RECTL bounds;
bounds.left = GETDW(DWP(n++));
bounds.top = GETDW(DWP(n++));
bounds.right = GETDW(DWP(n++));
bounds.bottom = GETDW(DWP(n++));
bounds.left = GETDW(DWP(n));
n++;
bounds.top = GETDW(DWP(n));
n++;
bounds.right = GETDW(DWP(n));
n++;
bounds.bottom = GETDW(DWP(n));
n++;

/* variable number of polygons */
poly_num = GETDW(DWP(n++));
poly_num = GETDW(DWP(n));
n++;

/* total number of points (in all polygons)*/
int total = GETDW(DWP(n++));
int total = GETDW(DWP(n));
n++;
int i;
PointFList *list = GdipAlloc (poly_num * sizeof (PointFList));
PointFList *current = list;
Expand All @@ -255,7 +277,8 @@ PolyPolygon (MetafilePlayContext *context, BYTE *data, BOOL compact)
#endif
/* read size of each polygon and allocate the required memory */
for (i = 0; i < poly_num; i++) {
current->num = GETDW(DWP(n++));
current->num = GETDW(DWP(n));
n++;
current->points = (GpPointF*) GdipAlloc (current->num * sizeof (GpPointF));
#ifdef DEBUG_EMF_2
printf ("\n\tSub Polygon #%d has %d points", i, current->num);
Expand All @@ -269,12 +292,15 @@ PolyPolygon (MetafilePlayContext *context, BYTE *data, BOOL compact)
int p;
for (p = 0; p < current->num; p++) {
if (compact) {
DWORD xy = GETDW(DWP(n++));
DWORD xy = GETDW(DWP(n));
n++;
pt->X = (xy & 0x0000FFFF);
pt->Y = (xy >> 16);
} else {
pt->X = GETDW(DWP(n++));
pt->Y = GETDW(DWP(n++));
pt->X = GETDW(DWP(n));
n++;
pt->Y = GETDW(DWP(n));
n++;
}
#ifdef DEBUG_EMF_3
printf ("\n\t\tpoly to %g,%g", pt->X, pt->Y);
Expand Down
6 changes: 6 additions & 0 deletions src/metafile-private.h
Expand Up @@ -60,6 +60,12 @@

#define gdip_get_metaheader(image) (&((GpMetafile*)image)->metafile_header)

#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define GETDW(x) (*(DWORD*)(data + (x)))
#else
#define GETDW(x) (GUINT32_FROM_LE(*(DWORD*)(data + (x))))
#endif

typedef struct {
void *ptr;
int type;
Expand Down
27 changes: 20 additions & 7 deletions src/wmfcodec.c
Expand Up @@ -92,6 +92,12 @@ GetColor (WORD w1, WORD w2)
return color;
}

#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define GETW(x) (*(WORD*)(data + (x)))
#else
#define GETW(x) (GUINT16_FROM_LE(*(WORD*)(data + (x))))
#endif

#define GetParam(x,y) GetWORD((6 + ((x) << 1)), (y))


Expand All @@ -118,8 +124,10 @@ Polygon (MetafilePlayContext *context, BYTE *data, int len)

int n = 2;
for (p = 0, pt = points; p < num; p++, pt++) {
pt->X = GETW(WP(n++));
pt->Y = GETW(WP(n++));
pt->X = GETW(WP(n));
n++;
pt->Y = GETW(WP(n));
n++;
#ifdef DEBUG_WMF
printf ("\n\tpoly to %g,%g", pt->X, pt->Y);
#endif
Expand Down Expand Up @@ -147,8 +155,10 @@ Polyline (MetafilePlayContext *context, BYTE *data)
SHORT y1 = GETW(WP3);
int n = 4;
for (p = 1; p < num; p++) {
SHORT x2 = GETW(WP(n++));
SHORT y2 = GETW(WP(n++));
SHORT x2 = GETW(WP(n));
n++;
SHORT y2 = GETW(WP(n));
n++;
#ifdef DEBUG_WMF_2
printf ("\n\tdraw from %d,%d to %d,%d", x1, y1, x2, y2);
#endif
Expand Down Expand Up @@ -180,7 +190,8 @@ PolyPolygon (MetafilePlayContext *context, BYTE *data)
int n = 2;
/* read size of each polygon and allocate the required memory */
for (i = 0; i < poly_num; i++) {
current->num = GETW(WP(n++));
current->num = GETW(WP(n));
n++;
current->points = (GpPointF*) GdipAlloc (current->num * sizeof (GpPointF));
#ifdef DEBUG_WMF_2
printf ("\n\tSub Polygon #%d has %d points", i, current->num);
Expand All @@ -194,8 +205,10 @@ PolyPolygon (MetafilePlayContext *context, BYTE *data)
GpPointF *pt = current->points;
int p;
for (p = 0; p < current->num; p++) {
pt->X = GETW(WP(n++));
pt->Y = GETW(WP(n++));
pt->X = GETW(WP(n));
n++;
pt->Y = GETW(WP(n));
n++;
#ifdef DEBUG_WMF_3
printf ("\n\t\tpoly to %g,%g", pt->X, pt->Y);
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/wmfcodec.h
Expand Up @@ -33,8 +33,6 @@
if (params < (x)) goto cleanup; \
} while (0)

#define GETDW(x) (*(DWORD*)(data + (x)))
#define GETW(x) (*(WORD*)(data + (x)))
#define RECORDSIZE 0
#define FUNCTION 4
#define WP1 6
Expand Down

0 comments on commit 4133fea

Please sign in to comment.