Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42345

ST_BUFFER: Assertion `n < SINUSES_CALCULATED*2+1' failed in get_n_sincos(); the test case of MDEV-32303 still crashes after the fixes of MDEV-31267 and MDEV-41458

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 13.3
    • None
    • GIS
    • None

    Description

      Problem

      ST_BUFFER() with huge coordinates, or with a huge distance applied to the union of two lines, still aborts a debug build in get_n_sincos() (sql/item_geofunc.cc) and crashes a build without assertions. The test case of MDEV-32303, which was closed as a duplicate of MDEV-31267, crashes current main. The changes of MDEV-31267 and of MDEV-41458 are both present in the tested source.

      How to repeat

      Fresh server, no tables, default settings. The test case of MDEV-32303:

      SELECT ( ST_BUFFER ( ST_GEOMFROMTEXT ( 'LINESTRING(1e308 1e308,-1e308 -1e308)' ) , 5 ) ) ;

      and a second statement found by fuzzing:

      SELECT ST_BUFFER(ST_UNION(MULTILINESTRINGFROMTEXT('MULTILINESTRING((3 4, 2 5, 7 6, 1 8))'), MULTILINESTRINGFROMTEXT('MULTILINESTRING((3 4, 3 1, 2 7, 4 2, 6 2, 1 5))')), 1e308) IS NULL AS r;

      For each build I started a fresh server on an empty data directory three times (13.3.0 main at commit 392818112aa1738005b977c21387d272b4287842, --no-defaults, TCP) and ran each statement once. Both statements crashed the server in 3 of 3 runs on a debug build with assertions, on an ASan/UBSan build, and on an optimized build without DBUG assertions (the optimized build has coverage instrumentation).

      Actual result

      Debug and ASan/UBSan builds, SIGABRT:

      sql/item_geofunc.cc:1724: void get_n_sincos(int, double *, double *): Assertion `n < SINUSES_CALCULATED*2+1' failed.

      Optimized build: signal 11. In the original fuzzer statement (a longer variant of the second statement above) the stack was Item_func_buffer::Transporter::add_edge_buffer called from Item_func_buffer::Transporter::add_point, Gis_multi_line_string::store_shapes and Item_func_buffer::val_str, which is the function named in MDEV-32303. I did not capture the stack of the two statements above on the optimized build.

      Notes

      • The tested source contains the change of MDEV-31267 (the clamp of t in Gcalc_heap::Info::calc_intersection_xy, sql/gcalc_slicescan.cc) and the change of MDEV-41458 (hypot() in calculate_perpendicular and the rewritten cosab in fill_gap, sql/item_geofunc.cc). I compared the source with both patches. The source tree HEAD was the then current main (39281811).
      • The distance matters. The second statement with the distance 1e300, 1e200, 1e100, 1e20 or 1 did not crash (one run each, debug build). A single MULTILINESTRING with the distance 1e308 did not crash either, and neither did the test case of MDEV-39751 (ST_BUFFER(ST_GEOMFROMTEXT('LINESTRING(0 0, 1 1, 2 2)'), 1e308)). Only the buffer of the ST_UNION of two MULTILINESTRING values at 1e308 crashed.
      • I did not trace where n leaves its range, and I did not test releases other than main.

      Attachments

        Activity

          People

            Unassigned Unassigned
            hacker_zheng Wang Zheng
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.