Skip to content

Commit

Permalink
Fixing invalid data access in unicode character mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
gershnik committed Jan 7, 2025
1 parent f6d5127 commit 1773cdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/inc/sys_string/impl/unicode/mappings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace sysstr::util
m_mapped(mapped)
{}
template<utf_encoding Enc, class OutIt>
auto write(char32_t c, OutIt dest) const noexcept(noexcept(*dest++ = utf_char_of<Enc>())) -> OutIt
static auto write(char32_t c, OutIt dest) noexcept(noexcept(*dest++ = utf_char_of<Enc>())) -> OutIt
{
if constexpr (Enc == utf32)
{
Expand All @@ -67,7 +67,7 @@ namespace sysstr::util
}
}
template<utf_encoding Enc, class OutIt>
auto write(const char16_t * begin, const char16_t * end, OutIt dest) const noexcept(noexcept(*dest++ = utf_char_of<Enc>())) -> OutIt
static auto write(const char16_t * begin, const char16_t * end, OutIt dest) noexcept(noexcept(*dest++ = utf_char_of<Enc>())) -> OutIt
{
if constexpr (Enc == utf16)
{
Expand All @@ -80,7 +80,7 @@ namespace sysstr::util
{
decoder.put(*begin++);
if (!decoder.done())
decoder.put(m_mapped[*begin++]); //no need to bounds check, we know end is good
decoder.put(*begin++); //no need to bounds check, we know end is good
dest = write<Enc>(decoder.value(), dest);
}
return dest;
Expand Down
2 changes: 2 additions & 0 deletions test/test_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ TEST_CASE( "Case conversion", "[general]" ) {
CHECK(S("ΑΣͺΑ").to_lower() == S("ασͺα"));

CHECK(S("βους").to_upper() == S("ΒΟΥΣ"));

CHECK(S("\U00010400").to_lower() == S("\U00010428"));
}

TEST_CASE( "Trim", "[general]" ) {
Expand Down

0 comments on commit 1773cdb

Please sign in to comment.