storesafe / cordova-sqlite-evcore-extbuild-free

Cordova sqlite plugin with Android performance enhancements for PhoneGap Build, GPL v3 or commercial license options
Other
24 stars 13 forks source link

Crash when using Samaritan letter #37

Closed brodycj closed 5 years ago

brodycj commented 6 years ago

Attempt to execute SQL statement that returns result with Samaritan letter will trigger a crash due to a bug in litehelpers / Android-sqlite-evcore-native-driver-free recently spotted by @brodybits. Here is a reproduction test case with Samaritan Bit letter (ref: https://www.compart.com/en/unicode/U+0801):

        it(suiteName + 'string parameter value manipulation test with UTF-8 3-byte character Samaritan Bit (\\U+0801)', function(done) {
          var db = openDatabase("UTF8-0801-string-upper-value-test.db", "1.0", "Demo", DEFAULT_SIZE);

          db.transaction(function(tx) {

            tx.executeSql('SELECT UPPER(?) AS myresult', ['a\u0801.'], function(ignored, rs) {
              expect(rs).toBeDefined();
              expect(rs.rows).toBeDefined();
              expect(rs.rows.length).toBe(1);
              expect(rs.rows.item(0).myresult).toBe('Aࠁ.');

              // Close (plugin only) & finish:
              (isWebSql) ? done() : db.close(done, done);
            });
          }, function(error) {
            // NOT EXPECTED:
            expect(false).toBe(true);
            expect(error.message).toBe('--');
            // Close (plugin only) & finish:
            (isWebSql) ? done() : db.close(done, done);
          });
        }, MYTIMEOUT);

The following patch to litehelpers / Android-sqlite-evcore-native-driver-free would resolve this issue:

diff --git a/native/sqlc.c b/native/sqlc.c
index 2ad1092..cfbe29f 100644
--- a/native/sqlc.c
+++ b/native/sqlc.c
@@ -491,7 +491,7 @@ const char *sqlc_evcore_qc_execute(sqlc_handle_t qc, const char * batch_json, in
                     pi += 1;
                   } else if (pc >= 32 && pc < 127) {
                     rr[rrlen++] = pptext[pi++];
-                  } else if (pc > 0xe0) {
+                  } else if (pc >= 0xe0) {
                     rr[rrlen++] = pptext[pi++];
                     rr[rrlen++] = pptext[pi++];
                     rr[rrlen++] = pptext[pi++];
brodycj commented 5 years ago

Now resolved