metal_chem parser OOB on blank/comment lines
Maintainers usually reply within 1 day
@BenWibking is already working on this.
Since Mar 3, 2026.
Assessment
This issue has not been assessed yet.
Description
metal_chem table parser can read out-of-bounds on blank/comment-only input
Summary
actual_network_init() in networks/metal_chem/actual_network_data.cpp assumes each scanned line has at least one character while skipping comments (line[0] != '#'). A blank line can trigger out-of-bounds access, and a comment-only/EOF file path gives weak validation behavior.
Severity
High
Affected Code
networks/metal_chem/actual_network_data.cpp- comment-skip loop around line 28
- header validation around lines 35-36
Why This Is a Bug
- Accessing
line[0]whenline.empty()is undefined behavior. - If the file has only comments or terminates before a data header, the current flow does not robustly detect that no header was found before checking format.
- This is initialization-path code; failure can abort setup or silently misdiagnose malformed inputs.
Proposed Patch
Harden parsing by:
- Ignoring empty lines while scanning for header.
- Tracking whether a non-comment header line was found.
- Throwing a clear error if missing header before format checks.
--- a/networks/metal_chem/actual_network_data.cpp
+++ b/networks/metal_chem/actual_network_data.cpp
@@
- // Skip comments and read until the first non-comment line
- while (std::getline(file, line)) {
- if (line[0] != '#') {
- break;
- }
- }
+ // Skip comments/blank lines and read until the first data/header line
+ bool found_header = false;
+ while (std::getline(file, line)) {
+ if (line.empty()) {
+ continue;
+ }
+ if (line[0] == '#') {
+ continue;
+ }
+ found_header = true;
+ break;
+ }
+
+ if (!found_header) {
+ throw std::runtime_error("ERROR: file " + filename + " has no data/header line.");
+ }
@@
- if (line.find(',') == std::string::npos) {
+ if (line.find(',') == std::string::npos) {
throw std::runtime_error("ERROR: file " + filename + " should contain the number of rows and columns in the format 'RR, CC'");
}
Validation
- Run with a valid
Semenov_PlanckOpacity.datand confirm initialization still succeeds. - Add a blank line before the first non-comment line; ensure no crash.
- Test a comment-only file and confirm clear exception message.
- Dominant language
- C++
- Stars
- 44
- Forks
- 46
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 10
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AMReX-Astro/Microphysics
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
AMReX-Astro/Microphysics#2104 · 3 comments ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 55/100
AMReX-Astro/Microphysics#2097 · 1 comment ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 72/100
AMReX-Astro/Microphysics#2096 ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 66/100
AMReX-Astro/Microphysics#2095 · 1 comment ·
Maintainers usually reply within 1 day
-
ai-code-audit nse
Difficulty 3/5 1-2 days Newbie friendliness 68/100
AMReX-Astro/Microphysics#2075 ·
Maintainers usually reply within 1 day
All issues in AMReX-Astro/Microphysics
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
metasequoiaime/msime#9113 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
tone-3000/tone3000-plugin#257 · 1 comment ·
Maintainers usually reply within 1 day
-
Locked plugin flip-flops position on every refresh after being disabledPossibly taken @Illustar0 claimed this today. Openissue report
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
ModOrganizer2/modorganizer#2449 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
enhancement P5
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
open-astro/AlpacaBridge#1468 ·
Maintainers usually reply within 1 day