Uploaded image for project: 'Couchbase Lite'
  1. Couchbase Lite
  2. CBL-4470

FLTimestamp_ToString() could return a slice with a wrong size

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • Beryllium
    • 3.1.0
    • LiteCore
    • Security Level: Public
    • None
    • LiteCore 106
    • 1

    Description

      This is found while using Swift Todo that is implemented by using CBL-C during the test fest.

      Here is the line that has the problem:

      https://github.com/couchbaselabs/mobile-training-todo/blob/release/helium/swift/Todo/Model/AppLogic-C.swift#L221

      The result FLStringResult has size = 29 instead of 24. As a result,  a wrong date-time string is written into the database.

      Here is an example : 

      "createdAt": "2023-04-26T00:56:23.563Z\u0004\t(\u0001",

      Note: The same issue doesn't happen when using the same call in CBL iOS's Objective-C Tests.

      Analysis:
      https://github.com/couchbase/fleece/blob/release/3.1/Fleece/API_Impl/Fleece.cc#L57

      1. From the code linked above, the strlen() function could return a wrong size.

      2. FormatISO8601Date() already returns the slice object with the correct size, the fix could be just creating the FLStringResult result with the returned slice object as follows

      FLStringResult FLTimestamp_ToString(FLTimestamp timestamp, bool asUTC) FLAPI {
          char str[kFormattedISO8601DateMaxSize];
          slice s = FormatISO8601Date(str, timestamp, asUTC);
          return FLSlice_Copy(s);
      } 

      Attachments

        Issue Links

          Activity

            People

              jianmin.zhao Jianmin Zhao
              pasin Pasin Suriyentrakorn
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty