From 0df468c569d58428e4a9acb571cd12e928550cc8 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 10 Jan 2025 04:39:32 +0100 Subject: [PATCH] Fix/workaround crash under UBSAN on OpenFileGDB driver with test_ogrsf -all_drivers --- autotest/ogr/ogr_basic_test.py | 5 ++++- ogr/ogrsf_frmts/openfilegdb/ogropenfilegdb_generate_uuid.cpp | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/autotest/ogr/ogr_basic_test.py b/autotest/ogr/ogr_basic_test.py index ec91a3647f30..172cca476dd8 100755 --- a/autotest/ogr/ogr_basic_test.py +++ b/autotest/ogr/ogr_basic_test.py @@ -448,8 +448,11 @@ def test_ogr_basic_10(): if test_cli_utilities.get_test_ogrsf_path() is None: pytest.skip() + # --config OPENFILEGDB_REPRODUCIBLE_UUID=YES helps avoiding unsigned-integer-overflow + # under UBSAN. ret = gdaltest.runexternal( - test_cli_utilities.get_test_ogrsf_path() + " -all_drivers" + test_cli_utilities.get_test_ogrsf_path() + + " -all_drivers --config OPENFILEGDB_REPRODUCIBLE_UUID=YES" ) assert "INFO" in ret diff --git a/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdb_generate_uuid.cpp b/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdb_generate_uuid.cpp index a8aa87b1341e..8abf3e6a6133 100644 --- a/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdb_generate_uuid.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdb_generate_uuid.cpp @@ -77,7 +77,9 @@ std::string OFGDBGenerateUUID(bool bInit) // from the same seed on all platforms. const auto reproducibleRand = [&nCounterLocal]() { - nCounterLocal = nCounterLocal * 1103515245U + 12345U; + nCounterLocal = static_cast( + (static_cast(nCounterLocal) * 1103515245U + 12345U) & + UINT32_MAX); return (nCounterLocal / 65536U) % 32768U; };