Skip to content

Check for NULL from proj_as_proj_string in proj_factors derived CRS handling#4705

Closed
ClayWarren wants to merge 3 commits intoOSGeo:masterfrom
ClayWarren:master
Closed

Check for NULL from proj_as_proj_string in proj_factors derived CRS handling#4705
ClayWarren wants to merge 3 commits intoOSGeo:masterfrom
ClayWarren:master

Conversation

@ClayWarren
Copy link

Motivation

  • A code path in proj_factors() for derived projected CRS constructed a std::string from the return value of proj_as_proj_string() without checking for NULL, which can occur when an object is not exportable or on export error and causes undefined behavior/crash.
  • The change prevents denial-of-service / crash scenarios when processing crafted or non-exportable CRS definitions while preserving existing functionality.

Description

  • Add a NULL check for the result of proj_as_proj_string() and return safely (after cleaning up) if export fails, avoiding construction of std::string from NULL in the derived projected CRS branch. (modified src/factors.cpp).
  • When rebuilding an operation from the trimmed PROJ string, check the result of proj_create() and return safely on failure instead of relying only on assert() (modified src/factors.cpp).
  • Add a regression unit test that constructs a derived projected CRS that cannot be exported to a PROJ string and asserts that proj_factors() returns an error condition rather than crashing (added test in test/unit/gie_self_tests.cpp).

Testing

  • Configured with CMake (-DCMAKE_BUILD_TYPE=Release) successfully in this environment. (succeeded)

  • Built the project with cmake --build successfully and produced binaries. (succeeded)

  • Exercised the produced proj binary with a simple projection invocation (./build/bin/proj +proj=merc +ellps=WGS84) which produced expected numeric output. (succeeded)

  • AI/LLM (Codex Security in research preview) supported my development of this PR

  • Tests added

  • Added clear title that can be used to generate release notes

ClayWarren and others added 3 commits March 7, 2026 13:43
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ference-in-proj_factors

Check for NULL from proj_as_proj_string in proj_factors derived CRS handling
@ClayWarren ClayWarren closed this by deleting the head repository Mar 7, 2026
@rouault
Copy link
Member

rouault commented Mar 7, 2026

@ClayWarren Why did you delete this PR ? This looked good to me

@ClayWarren
Copy link
Author

I deleted my fork, I'm still learning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants