Skip to content
Permalink
Browse files

Fix signed 32bit integer overflow in PostgreSQL provider

Fixes #13958
Includes test for signed integer attributes
  • Loading branch information
Sandro Santilli
Sandro Santilli committed Feb 16, 2016
1 parent a15f51e commit 2bd7f446b4dd368968f23b990262c5e8a5a83f80
Showing with 25 additions and 0 deletions.
  1. +6 −0 src/providers/postgres/qgspostgresconn.cpp
  2. +19 −0 tests/src/python/test_provider_postgres.py
@@ -1221,6 +1221,9 @@ qint64 QgsPostgresConn::getBinaryInt( QgsPostgresResult &queryResult, int row, i
oid = *( quint16 * )p;
if ( mSwapEndian )
oid = ntohs( oid );
/* cast to signed 16bit
* See http://hub.qgis.org/issues/14262 */
oid = ( qint16 )oid;
break;

case 6:
@@ -1268,6 +1271,9 @@ qint64 QgsPostgresConn::getBinaryInt( QgsPostgresResult &queryResult, int row, i
oid = *( quint32 * )p;
if ( mSwapEndian )
oid = ntohl( oid );
/* cast to signed 32bit
* See http://hub.qgis.org/issues/14262 */
oid = ( qint32 )oid;
break;
}

@@ -147,6 +147,25 @@ def test_unique(features, num_features):
self.assertTrue(vl.isValid())
test_unique([f for f in vl.getFeatures()], 4)

# See http://hub.qgis.org/issues/14262
def testSignedIdentifiers(self):
def test_query_attribute(dbconn, query, att, val, fidval):
ql = QgsVectorLayer('%s table="%s" (g) key=\'%s\' sql=' % (dbconn, query.replace('"', '\\"'), att), "testgeom", "postgres")
print query, att
assert(ql.isValid())
features = ql.getFeatures()
att_idx = ql.fieldNameIndex(att)
count = 0
for f in features:
count += 1
self.assertEqual(f.attributes()[att_idx], val)
#self.assertEqual(f.id(), val)
self.assertEqual(count, 1)
test_query_attribute(self.dbconn, '(SELECT -1::int4 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -1::int2 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -1::int8 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -65535::int8 i, NULL::geometry(Point) g)', 'i', -65535, 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit 2bd7f44

Please sign in to comment.
You can’t perform that action at this time.