Skip to content

Commit

Permalink
Fix crash when reading cjson with invalid layer data (#1636)
Browse files Browse the repository at this point in the history
* Fix crash when reading cjson with invalid layer data

If a script adds atoms or bonds, but not layers, it's skipped

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis authored Mar 2, 2024
1 parent 12e5606 commit 7061aac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ concurrency:

env:
# Don't build python 2.7, pypy, or 32-bit wheels or Mac arm64 on Py3.8
CIBW_SKIP: "cp36-* cp37-* cp311-* cp38-macosx_arm64 pp* *-musllinux_* *-manylinux_i686 *-win32"
CIBW_SKIP: "cp36-* cp37-* cp311-manylinux* cp312-manylinux* cp38-macosx_arm64 pp* *-musllinux_* *-manylinux_i686 *-win32"

# Need to do some setup before repairing the wheel on linux...
CIBW_REPAIR_WHEEL_COMMAND_LINUX: bash scripts/github-actions/repair_command_linux.sh
Expand Down
7 changes: 4 additions & 3 deletions avogadro/io/cjsonformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ bool CjsonFormat::deserialize(std::istream& file, Molecule& molecule,
json layerJson = atoms["layer"];
if (isNumericArray(layerJson)) {
auto& layer = LayerManager::getMoleculeInfo(&molecule)->layer;
for (Index i = 0; i < atomCount; ++i) {
for (Index i = 0; i < atomCount && i < layerJson.size(); ++i) {
while (layerJson[i] > layer.maxLayer()) {
layer.addLayer();
}
Expand All @@ -242,8 +242,9 @@ bool CjsonFormat::deserialize(std::istream& file, Molecule& molecule,

// are there bond labels?
json bondLabels = bonds["labels"];
if (bondLabels.is_array() && bondLabels.size() == molecule.bondCount()) {
for (unsigned int i = 0; i < molecule.bondCount(); ++i) {
if (bondLabels.is_array()) {
for (unsigned int i = 0;
i < molecule.bondCount() && i < bondLabels.size(); ++i) {
molecule.setBondLabel(i, bondLabels[i]);
}
}
Expand Down

0 comments on commit 7061aac

Please sign in to comment.