Skip to content

Commit 9f03327

Browse files
committed
feat(core): marker validation 🙀
- validate marker number when going in or out of the context #9119
1 parent 36c5b9d commit 9f03327

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

core/src/kmx/kmx_plus.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ static_assert(LDML_UC_SENTINEL == UC_SENTINEL, "mismatch: LDML_UC_SENTINEL");
319319
static_assert(LDML_MARKER_CODE == CODE_DEADKEY, "mismatch: LDML_MARKER_CODE");
320320
static_assert(LDML_MARKER_ANY_INDEX < UC_SENTINEL, "expected LDML_MARKER_ANY_INDEX < UC_SENTINEL");
321321

322+
/** @returns true if a valid marker per spec */
323+
static inline bool is_valid_marker(KMX_DWORD marker_no) {
324+
return ((marker_no == LDML_MARKER_ANY_INDEX) || (marker_no >= LDML_MARKER_MIN_INDEX && marker_no <= LDML_MARKER_MAX_INDEX));
325+
}
326+
322327
/* ------------------------------------------------------------------
323328
* bksp section
324329
------------------------------------------------------------------ */

core/src/ldml/ldml_processor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,6 @@ ldml_processor::emit_text(km_kbp_state *state, const std::u32string &str) {
373373
it++; // consume LDML_MARKER_CODE
374374
assert(it < str.end());
375375
const auto marker_no = *it;
376-
assert(marker_no >= LDML_MARKER_MIN_INDEX);
377-
assert(marker_no <= LDML_MARKER_ANY_INDEX);
378376
emit_marker(state, marker_no);
379377
} else {
380378
emit_text(state, ch);
@@ -389,10 +387,11 @@ ldml_processor::emit_text(km_kbp_state *state, km_kbp_usv ch) {
389387
state->actions().push_character(ch);
390388
}
391389

392-
void ldml_processor::emit_marker(km_kbp_state *state, KMX_DWORD marker_no) {
393-
// OK, push the marker
394-
state->actions().push_marker(marker_no);
395-
state->context().push_marker(marker_no);
390+
void
391+
ldml_processor::emit_marker(km_kbp_state *state, KMX_DWORD marker_no) {
392+
assert(km::kbp::kmx::is_valid_marker(marker_no));
393+
state->actions().push_marker(marker_no);
394+
state->context().push_marker(marker_no);
396395
}
397396

398397
size_t
@@ -406,6 +405,7 @@ ldml_processor::context_to_string(km_kbp_state *state, std::u32string &str) {
406405
if (last_type == KM_KBP_BT_CHAR) {
407406
str.insert(0, 1, c->character);
408407
} else if (last_type == KM_KBP_BT_MARKER) {
408+
assert(km::kbp::kmx::is_valid_marker(c->marker));
409409
prepend_marker(str, c->marker);
410410
} else {
411411
break;

0 commit comments

Comments
 (0)