php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71134 Segfault when using SpatiaLite
Submitted: 2015-12-16 12:00 UTC Modified: 2015-12-22 12:21 UTC
From: benjamin dot morel at gmail dot com Assigned:
Status: Closed Package: SQLite (PECL)
PHP Version: 7.0.0 OS: Fedora 23
Private report: No CVE-ID: None
 [2015-12-16 12:00 UTC] benjamin dot morel at gmail dot com
Description:
------------
I some very specific cases, SQLite3 with SpatiaLite produces a segfault.
Plus, when it does NOT segfault, it does not produce a result.

I thought originally that this was a problem with SpatiaLite itself, but my Travis CI builds show that this is working with PHP 5.6:

https://travis-ci.org/brick/geo/jobs/95249492

And segfaulting with PHP 7:

https://travis-ci.org/brick/geo/jobs/95249500

I've written a PHP script that I'm attaching below, that reproduces the problem.

First of all, you'll notice that the WKT version returns empty results, instead of returning the length as expected.

Then, the WKB version segfaults.

If you remove the WKT tests, the WKB tests do not segfault, but they do return empty results as well. This bug appears in specific conditions and was hard to track.

Test script:
---------------
<?php

// Initialize

$sqlite3 = new SQLite3(':memory:');
$sqlite3->loadExtension('mod_spatialite.so');

// Display versions

$statement = $sqlite3->query('SELECT sqlite_version(), spatialite_version()');
list ($sqliteVersion, $spatialiteVersion) = $statement->fetchArray(SQLITE3_NUM);

echo 'PHP version: ', PHP_VERSION, PHP_EOL;
echo 'SQLite version: ', $sqliteVersion, PHP_EOL;
echo 'SpatiaLite version: ', $spatialiteVersion, PHP_EOL;

// Reproduce the bug

$wkts = [
    'LINESTRING (0 0, 1 1)',
    'CIRCULARSTRING (0 0, 1 1, 2 2)',
    'CIRCULARSTRING (0 0, 1 1, 2 1)',
    'CIRCULARSTRING (0 0, 1 1, 3 1, 4 3, 5 3)',
    'COMPOUNDCURVE ((1 1, 2 1), CIRCULARSTRING (2 1, 1 1, 2 2))',
    'COMPOUNDCURVE (CIRCULARSTRING (0 0, 1 1, 2 1), (2 1, 2 2, 3 2, 3 3))'
];

$wkbs = [
    '01080000000300000000000000000000000000000000000000000000000000f03f000000000000f03f00000000000000400000000000000040',
    '01080000000300000000000000000000000000000000000000000000000000f03f000000000000f03f0000000000000040000000000000f03f',
    '010900000002000000010200000002000000000000000000f03f000000000000f03f0000000000000040000000000000f03f0108000000030000000000000000000040000000000000f03f000000000000f03f000000000000f03f00000000000000400000000000000040',
    '01090000000200000001080000000300000000000000000000000000000000000000000000000000f03f000000000000f03f0000000000000040000000000000f03f0102000000040000000000000000000040000000000000f03f000000000000004000000000000000400000000000000840000000000000004000000000000008400000000000000840'
];

// WKT tests

echo "WKT\n";

$sql = 'SELECT ST_Length(ST_GeomFromText(?, ?))';
$statement = $sqlite3->prepare($sql);

foreach ($wkts as $wkt) {
    $statement->bindValue(1, $wkt, SQLITE3_BLOB);
    $statement->bindValue(2, 0, SQLITE3_INTEGER);
    $result = $statement->execute();
    print_r($result->fetchArray(SQLITE3_NUM));
}

echo "WKB\n";

// WKB tests

$sql = 'SELECT ST_Length(ST_GeomFromWKB(?, ?))';
$statement = $sqlite3->prepare($sql);

foreach ($wkbs as $wkb) {
    $statement->bindValue(1, $wkb, SQLITE3_BLOB);
    $statement->bindValue(2, 0, SQLITE3_INTEGER);
    $result = $statement->execute();
    print_r($result->fetchArray(SQLITE3_NUM));
}


Expected result:
----------------
The lengths of the geometries should be returned.

Actual result:
--------------
Segmentation fault.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-22 12:21 UTC] benjamin dot morel at gmail dot com
-Status: Open +Status: Closed
 [2015-12-22 12:21 UTC] benjamin dot morel at gmail dot com
Bug not present in PHP 7.0.1, this has been fixed. Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC