tools/source/misc/json_writer.cxx |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 2fe581d916b76d613742c983731fb4a10b4ee95f
Author:     Jaume Pujantell <[email protected]>
AuthorDate: Tue Apr 18 10:34:47 2023 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Apr 27 12:13:37 2023 +0200

    fix bug in json_writer
    
    Ruler stores null-terminated strings in fixed length char arrays, so when 
creating a JSON
    a string might end earlier that it's size sugsests.
    
    Change-Id: Icdcaf35f9ce54c24dcd36368dc49bb688a2a65ce
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150542
    Reviewed-by: Michael Meeks <[email protected]>
    Tested-by: Jenkins

diff --git a/tools/source/misc/json_writer.cxx 
b/tools/source/misc/json_writer.cxx
index e7a0f55fd6c2..3111cac2f816 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -236,7 +236,8 @@ void JsonWriter::put(std::string_view pPropName, 
std::string_view rPropVal)
     ++mPos;
 
     // copy and perform escaping
-    for (size_t i = 0; i < rPropVal.size(); ++i)
+    bool bReachedEnd = false;
+    for (size_t i = 0; i < rPropVal.size() && !bReachedEnd; ++i)
     {
         char ch = rPropVal[i];
         switch (ch)
@@ -251,6 +252,9 @@ void JsonWriter::put(std::string_view pPropName, 
std::string_view rPropVal)
             case '\\':
                 writeEscapedSequence(ch, mPos);
                 break;
+            case 0:
+                bReachedEnd = true;
+                break;
             case '\xE2': // Special processing of U+2028 and U+2029
                 if (i + 2 < rPropVal.size() && rPropVal[i + 1] == '\x80'
                     && (rPropVal[i + 2] == '\xA8' || rPropVal[i + 2] == 
'\xA9'))

Reply via email to