From a2b573aa58effb3f42f4601723866e2e1e9dd703 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Sun, 31 Mar 2024 06:40:21 -0700 Subject: [PATCH] [view_curses] check color Related to #1245 --- src/base/ansi_scrubber.cc | 5 ++++- src/third-party/prqlc-c/Cargo.toml | 2 +- src/third-party/rapidyaml/ryml_all.hpp | 2 +- src/view_curses.cc | 13 ++++++++----- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/base/ansi_scrubber.cc b/src/base/ansi_scrubber.cc index e83853aa..379a71b8 100644 --- a/src/base/ansi_scrubber.cc +++ b/src/base/ansi_scrubber.cc @@ -323,7 +323,10 @@ scrub_ansi_string(std::string& str, string_attrs_t* sa) semi_pred); auto color_index = scn::scan_value( color_index_pair.first.to_string_view()); - if (!color_index.has_value()) { + if (!color_index.has_value() + || color_index.value() < 0 + || color_index.value() > 255) + { break; } if (ansi_code == 38) { diff --git a/src/third-party/prqlc-c/Cargo.toml b/src/third-party/prqlc-c/Cargo.toml index 52eddeea..f66183a0 100644 --- a/src/third-party/prqlc-c/Cargo.toml +++ b/src/third-party/prqlc-c/Cargo.toml @@ -14,7 +14,7 @@ default = [] # We produce both of these at the moment, but could consider refining this. ref # https://github.com/rust-lang/cargo/issues/8607 & # https://github.com/rust-lang/rust/issues/59302 -crate_type = ["staticlib", "cdylib"] +crate_type = ["staticlib"] doctest = false test = false doc = false diff --git a/src/third-party/rapidyaml/ryml_all.hpp b/src/third-party/rapidyaml/ryml_all.hpp index e4b32755..03734a16 100644 --- a/src/third-party/rapidyaml/ryml_all.hpp +++ b/src/third-party/rapidyaml/ryml_all.hpp @@ -1766,7 +1766,7 @@ __inline__ static void trap_instruction(void) /* Known problem: * Same problem and workaround as Thumb mode */ } -#elif defined(__aarch64__) && defined(__APPLE__) +#elif defined(__aarch64__) && defined(__APPLE__) && defined(__clang__) #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BULTIN_DEBUGTRAP #elif defined(__aarch64__) #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION diff --git a/src/view_curses.cc b/src/view_curses.cc index 6525c54e..f5835a59 100644 --- a/src/view_curses.cc +++ b/src/view_curses.cc @@ -430,14 +430,17 @@ view_curses::mvwattrline(WINDOW* window, short cur_fg, cur_bg; pair_content(cur_pair, &cur_fg, &cur_bg); - if (fg_color[lpc] != -1 && bg_color[lpc] == -1 - && base_attrs.ta_bg_color.value_or(0) >= 0) + if (fg_color[lpc] >= 0 + && fg_color[lpc] < view_colors::vc_active_palette->tc_palette.size() + && bg_color[lpc] == -1 && base_attrs.ta_bg_color.value_or(0) >= 0 + && base_attrs.ta_bg_color.value_or(0) + < view_colors::vc_active_palette->tc_palette.size()) { const auto& fg_color_info - = view_colors::vc_active_palette->tc_palette[fg_color[lpc]]; + = view_colors::vc_active_palette->tc_palette.at(fg_color[lpc]); const auto& bg_color_info - = view_colors::vc_active_palette - ->tc_palette[base_attrs.ta_bg_color.value_or(0)]; + = view_colors::vc_active_palette->tc_palette.at( + base_attrs.ta_bg_color.value_or(0)); if (!fg_color_info.xc_lab_color.sufficient_contrast( bg_color_info.xc_lab_color))