diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 21d3e7cf..2b9e7ba2 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -1322,7 +1322,8 @@ public:
         inline void erase_characters(long count);
         inline void insert_blank_character();
         inline int32_t parse_sgr_38_48_parameters(vte::parser::Params const& params,
-                                                  unsigned int *index);
+                                                  unsigned int *index,
+                                                  bool might_contain_color_space_id);
         inline void move_cursor_backward(vte::grid::column_t columns);
         inline void move_cursor_forward(vte::grid::column_t columns);
         inline void move_cursor_tab();
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 58791b95..efa33235 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -1802,7 +1802,8 @@ VteTerminalPrivate::seq_vertical_tab(vte::parser::Params const& params)
  * Increments @index to point to the last consumed parameter (not beyond). */
 int32_t
 VteTerminalPrivate::parse_sgr_38_48_parameters(vte::parser::Params const& params,
-                                               unsigned int *index)
+                                               unsigned int *index,
+                                               bool might_contain_color_space_id)
 {
         auto n_params = params.size();
         if (*index < n_params) {
@@ -1814,6 +1815,8 @@ VteTerminalPrivate::parse_sgr_38_48_parameters(vte::parser::Params const& params
                 case 2: {
                         if (G_UNLIKELY(*index + 3 >= n_params))
 				return -1;
+                        if (might_contain_color_space_id && *index + 5 <= n_params)
+			        *index += 1;
 
                         long param1, param2, param3;
                         if (G_UNLIKELY(!params.number_at_unchecked(*index + 1, param1) ||
@@ -1870,10 +1873,7 @@ VteTerminalPrivate::seq_character_attributes(vte::parser::Params const& params)
                         case 58:
                         {
                                 unsigned int index = 1;
-                                auto color = parse_sgr_38_48_parameters(subparams, &index);
-                                /* Bail out on additional colon-separated values. */
-                                if (G_UNLIKELY(index != subparams.size() - 1))
-                                        continue;
+                                auto color = parse_sgr_38_48_parameters(subparams, &index, true);
                                 if (G_LIKELY (color != -1)) {
                                         if (param0 == 38) {
                                                 m_defaults.attr.fore = color;
@@ -1979,16 +1979,13 @@ VteTerminalPrivate::seq_character_attributes(vte::parser::Params const& params)
                                 ++i;
                                 if (params.has_number_at_unchecked(i)) {
 					/* Only semicolons as separators. */
-                                        color = parse_sgr_38_48_parameters(params, &i);
+                                        color = parse_sgr_38_48_parameters(params, &i, false);
                                 } else if (params.has_subparams_at_unchecked(i)) {
 					/* The first separator was a semicolon, the rest are colons. */
                                         auto subparams = params.subparams_at_unchecked(i);
 
 					unsigned int index = 0;
-                                        color = parse_sgr_38_48_parameters(subparams, &index);
-					/* Bail out on additional colon-separated values. */
-                                        if (G_UNLIKELY(index != subparams.size() - 1))
-						break;
+                                        color = parse_sgr_38_48_parameters(subparams, &index, true);
 				} else {
 					break;
 				}
