Prevent out-of-bounds memory access on Compton profile data

This commit is contained in:
Paul Romano 2022-11-11 20:50:36 -06:00
parent 765df9115f
commit 6ede028b39

View file

@ -226,8 +226,9 @@ PhotonInteraction::PhotonInteraction(hid_t group)
// Create Compton profile CDF
auto n_profile = data::compton_profile_pz.size();
profile_cdf_ = xt::empty<double>({n_shell, n_profile});
for (int i = 0; i < profile_pdf_.shape(0); ++i) {
auto n_shell_compton = profile_pdf_.shape(0);
profile_cdf_ = xt::empty<double>({n_shell_compton, n_profile});
for (int i = 0; i < n_shell_compton; ++i) {
double c = 0.0;
profile_cdf_(i, 0) = 0.0;
for (int j = 0; j < n_profile - 1; ++j) {
@ -409,6 +410,13 @@ void PhotonInteraction::compton_scatter(double alpha, bool doppler,
double E_out;
this->compton_doppler(alpha, *mu, &E_out, i_shell, seed);
*alpha_out = E_out / MASS_ELECTRON_EV;
// It's possible for the Compton profile data to have more shells than
// there are in the ENDF data. Make sure the shell index doesn't end up
// out of bounds.
if (*i_shell >= shells_.size()) {
*i_shell = -1;
}
} else {
*i_shell = -1;
}