From 5d7d057edd6ada40e032c1d52b7f6cc39cc81a97 Mon Sep 17 00:00:00 2001 From: pford Date: Mon, 6 May 2024 03:30:26 -0600 Subject: [PATCH] Check for stoi out_of_range for FITS header parsing (#1369) * Check for stoi out_of_range then convert header value to long * Update changelog --------- Co-authored-by: Pam Harris --- CHANGELOG.md | 3 +++ src/ImageData/CompressedFits.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31cc83ffb..609e83f81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +* Fix crash when parsing FITS header long value ([#1366](https://github.com/CARTAvis/carta-backend/issues/1366)). + ### Changed * Move the loader cache to separate files ([#1021](https://github.com/CARTAvis/carta-backend/issues/1021)). * Improve the code style in HTTP server ([#1260](https://github.com/CARTAvis/carta-backend/issues/1260)). diff --git a/src/ImageData/CompressedFits.cc b/src/ImageData/CompressedFits.cc index 49ffa2e33..7e9c9dda5 100644 --- a/src/ImageData/CompressedFits.cc +++ b/src/ImageData/CompressedFits.cc @@ -414,6 +414,10 @@ void CompressedFits::AddHeaderEntry( } catch (std::invalid_argument) { // Set string value only entry->set_entry_type(CARTA::EntryType::STRING); + } catch (std::out_of_range) { + long lvalue = std::stol(value); + entry->set_numeric_value(lvalue); + entry->set_entry_type(CARTA::EntryType::INT); } } }