gnucash stable: Bug 798877 - Program crashes upon selection of CSV profile

Geert Janssens gjanssens at code.gnucash.org
Tue Apr 25 04:42:16 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/6a68872a (commit)
	from  https://github.com/Gnucash/gnucash/commit/0fd431d0 (commit)



commit 6a68872a90aeae475977cdf434bb8605f2bd8ca0
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Tue Apr 25 10:40:11 2023 +0200

    Bug 798877 - Program crashes upon selection of CSV profile
    
    Prevent reading data beyond the number of columns
    effectively present in each individual row.
    This affected only split related columns.
    Transaction related fields were properly
    safeguarded arleady.

diff --git a/gnucash/import-export/csv-imp/gnc-import-tx.cpp b/gnucash/import-export/csv-imp/gnc-import-tx.cpp
index da6dc61624..a73239d656 100644
--- a/gnucash/import-export/csv-imp/gnc-import-tx.cpp
+++ b/gnucash/import-export/csv-imp/gnc-import-tx.cpp
@@ -813,8 +813,11 @@ void GncTxImport::update_pre_trans_split_props (uint32_t row, uint32_t col, GncT
                     col_it++)
                 if (*col_it == old_type)
                 {
-                    auto col_num = col_it - m_settings.m_column_types.cbegin();
-                    auto value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col_num);
+                    auto value = std::string();
+                    auto col_num = static_cast<uint32_t>(col_it - m_settings.m_column_types.cbegin());
+
+                    if (col_num < std::get<PL_INPUT>(m_parsed_lines[row]).size())
+                        value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col_num);
                     split_props->add (old_type, value);
                 }
         }
@@ -833,14 +836,19 @@ void GncTxImport::update_pre_trans_split_props (uint32_t row, uint32_t col, GncT
                     col_it++)
                 if (*col_it == new_type)
                 {
-                    auto col_num = col_it - m_settings.m_column_types.cbegin();
-                    auto value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col_num);
+                    auto value = std::string();
+                    auto col_num = static_cast<uint32_t>(col_it - m_settings.m_column_types.cbegin());
+
+                    if (col_num < std::get<PL_INPUT>(m_parsed_lines[row]).size())
+                        value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col_num);
                     split_props->add (new_type, value);
                 }
         }
         else
         {
-            auto value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col);
+            auto value = std::string();
+            if (col < std::get<PL_INPUT>(m_parsed_lines[row]).size())
+                value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col);
             split_props->set(new_type, value);
         }
     }



Summary of changes:
 gnucash/import-export/csv-imp/gnc-import-tx.cpp | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)



More information about the gnucash-changes mailing list