missioncommand / mil-sym-java

(RETIRED) MIL-STD-2525 B and C rendering library and web service
Apache License 2.0
67 stars 36 forks source link

TacticalLines.FORDIF Overwrites Array #12

Closed ghost closed 9 years ago

ghost commented 9 years ago

With a map scale of 10,000 and a very small bounding box (WorldWind zoomed in to 2m scale, about 0.02x0.02 degree box), renderer throws exceptions repeatedly for a TacticalLines.FORDIF. Geometry isn't even within the bounding box.

arraysupport.java:3573 While creating "jaggies" for a Crossing Site / Water Crossing, Ford Difficult (G_M_BCD---****X), there is no array overrun protection.

Proposed fix:

if(drawJaggies)
while (dExtendLength < dWidth - 10 && pointCounter+2<pLinePoints.length)
{
    //dExtendLength = (double) n * 10;
    dExtendLength = (double) n * 5;
    pLinePoints[pointCounter] = lineutility.ExtendLine2Double(pt2, pt3, dExtendLength - dWidth, 0);
    pointCounter++;
    n++;
    //dExtendLength = (double) n * 10;
    dExtendLength = (double) n * 5;
    pLinePoints[pointCounter] = lineutility.ExtendLine2Double(pt4, pt5, dExtendLength - dWidth, 0);
    pointCounter++;
    n++;
}

Would also be nice if the geometry wasn't built when it is off screen as well.

mdeutch3 commented 9 years ago

An array safeguard has been added although the clipbounds calculation is supposed to prevent it from going past the array limit.

ghost commented 9 years ago

The clipbounds calculations don't seem to prevent a handful of those arraysupport elements from being generated.

In this case, my FORDIF isn't anywhere near the clip bounds, but it is still getting calculated and overflow the buffer.

ghost commented 9 years ago

Control points: -70.26063,2.2617817 -70.33023,2.295637 -70.26609,2.3389485 Scale: 10000 BBOX: -62.60009765625,1.3037109375,-62.596435546875,1.307373046875

Results in a clipBounds of java.awt.geom.Rectangle2D$Double[x=-50.0,y=-50.0,w=254.0,h=254.0]

dWidth is calculated at 2824, so dExtendedLength gets to 350 before it overruns the array.

michael-spinelli commented 9 years ago

Fixed, will be available in next release (.56)