Skip to content

Commit

Permalink
Fix A layer using a mask and a label with repeatdistance can crash (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Boudreault committed Sep 25, 2013
1 parent c4a70d7 commit f82d6c8
Showing 1 changed file with 49 additions and 40 deletions.
89 changes: 49 additions & 40 deletions maplabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,25 +351,28 @@ int msAddLabelGroup(mapObj *map, int layerindex, int classindex, shapeObj *shape
MS_IMAGE_RENDERER(maskLayer->maskimage)->getRasterBufferHandle(maskLayer->maskimage,&rb);
x = MS_NINT(point->x);
y = MS_NINT(point->y);
/* Using label repeatdistance, we might have a point with x/y below 0. See #4764 */
if (x >= 0 && x < rb.width && y >= 0 && y < rb.height) {
#ifdef USE_GD
if(rb.type == MS_BUFFER_BYTE_RGBA) {
if(rb.type == MS_BUFFER_BYTE_RGBA) {
alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x;
if(!*alphapixptr) {
/* label point does not intersect mask */
return MS_SUCCESS;
}
} else {
if(!gdImageGetPixel(rb.data.gd_img,x,y))
return MS_SUCCESS;
}
#else
assert(rb.type == MS_BUFFER_BYTE_RGBA);
alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x;
if(!*alphapixptr) {
/* label point does not intersect mask */
return MS_SUCCESS;
}
} else {
if(!gdImageGetPixel(rb.data.gd_img,x,y))
return MS_SUCCESS;
}
#else
assert(rb.type == MS_BUFFER_BYTE_RGBA);
alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x;
if(!*alphapixptr) {
/* label point does not intersect mask */
return MS_SUCCESS;
}
#endif
}
} else {
msSetError(MS_MISCERR, "Layer (%s) references references a mask layer, but the selected renderer does not support them", "msAddLabelGroup()", layerPtr->name);
return (MS_FAILURE);
Expand Down Expand Up @@ -543,54 +546,60 @@ int msAddLabel(mapObj *map, labelObj *label, int layerindex, int classindex, sha
if (point) {
int x = MS_NINT(point->x);
int y = MS_NINT(point->y);
/* Using label repeatdistance, we might have a point with x/y below 0. See #4764 */
if (x >= 0 && x < rb.width && y >= 0 && y < rb.height) {
#ifdef USE_GD
if(rb.type == MS_BUFFER_BYTE_RGBA) {
if(rb.type == MS_BUFFER_BYTE_RGBA) {
alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x;
if(!*alphapixptr) {
/* label point does not intersect mask */
return MS_SUCCESS;
}
} else {
if(!gdImageGetPixel(rb.data.gd_img,x,y)) {
return MS_SUCCESS;
}
}
#else
assert(rb.type == MS_BUFFER_BYTE_RGBA);
alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x;
if(!*alphapixptr) {
/* label point does not intersect mask */
return MS_SUCCESS;
}
} else {
if(!gdImageGetPixel(rb.data.gd_img,x,y)) {
return MS_SUCCESS;
}
}
#else
assert(rb.type == MS_BUFFER_BYTE_RGBA);
alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x;
if(!*alphapixptr) {
/* label point does not intersect mask */
return MS_SUCCESS;
}
#endif
}
} else if (labelpath) {
int i = 0;
for (i = 0; i < labelpath->path.numpoints; i++) {
int x = MS_NINT(labelpath->path.point[i].x);
int y = MS_NINT(labelpath->path.point[i].y);
/* Using label repeatdistance, we might have a point with x/y below 0. See #4764 */
if (x >= 0 && x < rb.width && y >= 0 && y < rb.height) {
#ifdef USE_GD
if (rb.type == MS_BUFFER_BYTE_RGBA) {
if (rb.type == MS_BUFFER_BYTE_RGBA) {
alphapixptr = rb.data.rgba.a + rb.data.rgba.row_step * y + rb.data.rgba.pixel_step*x;
if (!*alphapixptr) {
/* label point does not intersect mask */
msFreeLabelPathObj(labelpath);
return MS_SUCCESS;
}
} else {
if (!gdImageGetPixel(rb.data.gd_img, x, y)) {
msFreeLabelPathObj(labelpath);
return MS_SUCCESS;
}
}
#else
assert(rb.type == MS_BUFFER_BYTE_RGBA);
alphapixptr = rb.data.rgba.a + rb.data.rgba.row_step * y + rb.data.rgba.pixel_step*x;
if (!*alphapixptr) {
/* label point does not intersect mask */
msFreeLabelPathObj(labelpath);
return MS_SUCCESS;
}
} else {
if (!gdImageGetPixel(rb.data.gd_img, x, y)) {
msFreeLabelPathObj(labelpath);
return MS_SUCCESS;
}
}
#else
assert(rb.type == MS_BUFFER_BYTE_RGBA);
alphapixptr = rb.data.rgba.a + rb.data.rgba.row_step * y + rb.data.rgba.pixel_step*x;
if (!*alphapixptr) {
/* label point does not intersect mask */
msFreeLabelPathObj(labelpath);
return MS_SUCCESS;
}
#endif
}
}
}
} else {
Expand Down

0 comments on commit f82d6c8

Please sign in to comment.