Repository navigation
Fix out-of-bounds write when counting molecules per type - #14
Merged
Merged
Conversation
BaseSystem and SystemAM grew the per-type count vector by one element when they saw a new type index, then wrote to maxj[i]. A subsystem containing only a type-1 molecule (as PBSAM::make_subsystem builds for self- polarization) therefore wrote past the end of the vector, corrupting the heap and producing platform-dependent PBSAM results. Resize the vector to cover the type index, and count absent types as zero. Co-authored-by: Copilot <[email protected]> Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc
sobolevnrm
pushed a commit
to Electrostatics/apbs
that referenced
this pull request
Oct 25, 2026
pb_solvers cef00d7 fixes a heap-buffer-overflow in BaseSystem that made PBSAM results platform dependent (Electrostatics/pb_solvers#14). Refs #321 Co-authored-by: Copilot <[email protected]> Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc
sobolevnrm
added a commit
to Electrostatics/apbs
that referenced
this pull request
Oct 26, 2026
* Fix PBAM/PBSAM regression tests and test them in CI Restore the salt concentrations that were commented out in 2021, replace the obsolete pbsam-auto keyword with pbsam, and update the PBSAM reference energies for the solvent-dielectric scaling that pb_solvers 5671943 (2017) applied to energies to match forces. Add a PR-triggered Linux job that builds with PBAM/PBSAM enabled and runs their regression tests. Refs #321 Co-authored-by: Copilot <[email protected]> Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc * Fix out-of-bounds read in PBAM/PBSAM write parsing NOsh_parsePBAM and NOsh_parsePBSAM read writefmt[numwrite - 1] and writestem[numwrite - 1] even when the input had no write statement, indexing element -1. Only check the write format when a write exists. Refs #321 Co-authored-by: Copilot <[email protected]> Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc * Pin pb_solvers with the BaseSystem type-count fix pb_solvers cef00d7 fixes a heap-buffer-overflow in BaseSystem that made PBSAM results platform dependent (Electrostatics/pb_solvers#14). Refs #321 Co-authored-by: Copilot <[email protected]> Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc * Pin pb_solvers with the OpenBLAS applyMMat fix pb_solvers 8d254e5 makes PBSAM's matrix multiply work with OpenBLAS (Electrostatics/pb_solvers#15), which fixes the Linux PBSAM results. Refs #321 Co-authored-by: Copilot <[email protected]> Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc --------- Co-authored-by: Nathan Baker <[email protected]> Co-authored-by: Copilot <[email protected]> Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a heap-buffer-overflow in the
BaseSystemandSystemAMconstructors that corrupts memory during PBSAM runs.Problem
Both constructors count molecules per type with
if (i >= maxj.size()) maxj.push_back(0); maxj[i] = ....That grows the vector by only one element, so a type index more than one past the end writes out of bounds.
PBSAM::make_subsystembuilds a one-molecule system for each molecule type during self-polarization, so the type-1 subsystem writesmaxj[1]into a one-element vector.AddressSanitizer reports this as a heap-buffer-overflow from
PBSAM::initialize_pbsam.In APBS, the PBSAM regression test (
examples/pbsam-gly/gly_energyforce.in) gives the expected energy on macOS but 1.25E+306 on Ubuntu, where the self-polarization loop runs for hundreds of iterations without converging.See Electrostatics/apbs#321 and Electrostatics/apbs#323.
Fix
Resize the count vector to cover the type index, initializing new entries to −1 so that types absent from a subsystem end with a count of 0.
typect_is documented as the count of molecules of each type.Testing
pbamtest(160 tests) andpbsamtest(102 tests) pass on macOS.-fsanitize=address,undefinedruns the PBAM and PBSAM regression examples with no sanitizer reports and reproduces the expected energies.