Skip to content

fix: guard against empty band UB in lbl.equivalent_lines binding - #1184

Merged
olemke merged 1 commit into
atmtools:mainfrom
olemke:fix-ub-crash
Oct 9, 2026
Merged

olemke merged 1 commit into
atmtools:mainfrom
olemke:fix-ub-crash

Conversation

@olemke

@olemke olemke commented Oct 5, 2026

Copy link
Copy Markdown
Member

The lbl.equivalent_lines Python binding accessed band.front() without checking that the band was non-empty, so passing an empty absorption band invoked undefined behavior and crashed the interpreter instead of reporting a usable error. This PR adds an explicit validation step so that empty bands raise a proper ARTS_USER_ERROR, turning a hard crash into a catchable Python exception.

Changes

  • src/python_interface/py_lbl.cpp: In the lbl.equivalent_lines binding, the band size is now checked first and an ARTS_USER_ERROR("Cannot use an empty band in equivalent_lines") is thrown for empty bands, before any band.front() access. The lbl::voigt::ecs::ComputeData construction was also moved below the validation so no solver state is built for an invalid call.

The equivalent_lines Python binding dereferenced band.front()
before validating the band, causing undefined behavior for empty
bands. Add an ARTS_USER_ERROR guard for the empty-band case,
matching the error style of the C++ callee.
@olemke

olemke commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@riclarsson Is throwing an error ok or would you prefer a noop on an empty band input in the python interface for equivalent_lines? In the latter case, it would need to return some dummy values like

std::pair{ComplexTensor3(0, 0, 0), ComplexTensor3(0, 0, 0)}
# or
std::pair{ComplexTensor3(M, 0, 0), ComplexTensor3(M, 0, 0)}

to match the type of the later return.

@riclarsson

Copy link
Copy Markdown
Contributor

@olemke Explain tomorrow

@olemke
olemke merged commit aaa07df into atmtools:main Oct 9, 2026
9 checks passed
@olemke
olemke deleted the fix-ub-crash branch October 9, 2026 10:13
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