Пример #1
0
        public void TestContainsPointNoBufferOverrun2()
        {
            PointF[] data = new PointF[11];
            data[0] = new PointF(250, 208);
            data[1] = new PointF(247, 201);
            data[2] = new PointF(245, 208);
            data[3] = new PointF(245, 213);
            data[4] = new PointF(249, 215);
            data[5] = new PointF(251, 215);
            data[6] = new PointF(254, 215);
            data[7] = new PointF(251, 210);
            data[8] = new PointF(255, 209);
            data[9] = new PointF(254, 201);

            var offset = PolygonF.TestVertexNormalization(data);

            // test for a possible buffer overrun in the computation
            foreach (PointF garbagePoint in SimulatedBufferOverrunPoints)
            {
                data[data.Length - 1] = garbagePoint;
                unsafe
                {
                    fixed(PointF *points = data)
                    {
                        // inside PolygonF, the vertexCount is always exactly the expected array length
                        // which is 10 (the 11th point simulates garbage data beyond the array)
                        int vertexCount = data.Length - 1;

                        Assert.IsTrue(PolygonF.TestContains(new PointF(249, 209) - offset, points, vertexCount));
                    }
                }
            }
        }
Пример #2
0
        public void TestContainsPointNoBufferOverrun()
        {
            PointF[] data = new PointF[5];
            data[0] = new PointF(0, 0);
            data[1] = new PointF(1, 0);
            data[2] = new PointF(1, 1);
            data[3] = new PointF(0, 1);

            var offset = PolygonF.TestVertexNormalization(data);

            // test for a possible buffer overrun in the computation
            foreach (PointF garbagePoint in SimulatedBufferOverrunPoints)
            {
                data[data.Length - 1] = garbagePoint;
                unsafe
                {
                    fixed(PointF *points = data)
                    {
                        // inside PolygonF, the vertexCount is always exactly the expected array length
                        // which is 4 (the 5th point simulates garbage data beyond the array)
                        int vertexCount = data.Length - 1;

                        Assert.IsTrue(PolygonF.TestContains(new PointF(0.5f, 0.5f) - offset, points, vertexCount));                     // inside
                        Assert.IsFalse(PolygonF.TestContains(new PointF(0.5f, 1.5f) - offset, points, vertexCount));                    // above
                        Assert.IsFalse(PolygonF.TestContains(new PointF(0f, 1.5f) - offset, points, vertexCount));                      // above

                        Assert.IsTrue(PolygonF.TestContains(new PointF(0f, 0.5f) - offset, points, vertexCount));                       // left edge
                        Assert.IsFalse(PolygonF.TestContains(new PointF(1f, 0.5f) - offset, points, vertexCount));                      // right edge
                        Assert.IsTrue(PolygonF.TestContains(new PointF(0.5f, 0f) - offset, points, vertexCount));                       // bottom edge
                        Assert.IsFalse(PolygonF.TestContains(new PointF(0.5f, 1f) - offset, points, vertexCount));                      // top edge

                        Assert.IsTrue(PolygonF.TestContains(new PointF(0f, 0f) - offset, points, vertexCount));                         // bottom left corner
                        Assert.IsFalse(PolygonF.TestContains(new PointF(0f, 1f) - offset, points, vertexCount));                        // top left corner
                        Assert.IsFalse(PolygonF.TestContains(new PointF(1f, 0f) - offset, points, vertexCount));                        // bottom right corner
                        Assert.IsFalse(PolygonF.TestContains(new PointF(1f, 1f) - offset, points, vertexCount));                        // top right corner
                    }
                }
            }
        }