/ Check-in [e6bb7506]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a memory leak that could follow an IO error in the zipfile extension. And add other tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:e6bb750697c3c7ceb5ce41d216e8ef6a1d556822a3b55e0a007b4a03e194a7d9
User & Date: dan 2018-02-01 15:19:54
Context
2018-02-01
15:57
New assert() statements to help ensure that no other errors similar to [343634942dd54ab57b7] ever appear in the code. check-in: 5a70af1e user: drh tags: trunk
15:19
Fix a memory leak that could follow an IO error in the zipfile extension. And add other tests. check-in: e6bb7506 user: dan tags: trunk
01:13
When an index is based on a text representation of a numeric column in the original table, make sure the indexed value uses the canonical text representation of the numeric value in the table. Proposed fix for ticket [343634942dd54ab57b70]. check-in: 88e2ce91 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/misc/zipfile.c.

2013
2014
2015
2016
2017
2018
2019
2020
2021

2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036

2037
2038
2039
2040
2041
2042
2043
void zipfileFinal(sqlite3_context *pCtx){
  ZipfileCtx *p;
  ZipfileEOCD eocd;
  int nZip;
  u8 *aZip;

  p = (ZipfileCtx*)sqlite3_aggregate_context(pCtx, sizeof(ZipfileCtx));
  if( p==0 || p->nEntry==0 ) return;


  memset(&eocd, 0, sizeof(eocd));
  eocd.nEntry = p->nEntry;
  eocd.nEntryTotal = p->nEntry;
  eocd.nSize = p->cds.n;
  eocd.iOffset = p->body.n;

  nZip = p->body.n + p->cds.n + ZIPFILE_EOCD_FIXED_SZ;
  aZip = (u8*)sqlite3_malloc(nZip);
  if( aZip==0 ){
    sqlite3_result_error_nomem(pCtx);
  }else{
    memcpy(aZip, p->body.a, p->body.n);
    memcpy(&aZip[p->body.n], p->cds.a, p->cds.n);
    zipfileSerializeEOCD(&eocd, &aZip[p->body.n + p->cds.n]);
    sqlite3_result_blob(pCtx, aZip, nZip, zipfileFree);

  }

  sqlite3_free(p->body.a);
  sqlite3_free(p->cds.a);
}









|
<
>
|
|
|
|
|

|
|
|
|
|
|
|
|
|
>







2013
2014
2015
2016
2017
2018
2019
2020

2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
void zipfileFinal(sqlite3_context *pCtx){
  ZipfileCtx *p;
  ZipfileEOCD eocd;
  int nZip;
  u8 *aZip;

  p = (ZipfileCtx*)sqlite3_aggregate_context(pCtx, sizeof(ZipfileCtx));
  if( p==0 ) return;

  if( p->nEntry>0 ){
    memset(&eocd, 0, sizeof(eocd));
    eocd.nEntry = p->nEntry;
    eocd.nEntryTotal = p->nEntry;
    eocd.nSize = p->cds.n;
    eocd.iOffset = p->body.n;

    nZip = p->body.n + p->cds.n + ZIPFILE_EOCD_FIXED_SZ;
    aZip = (u8*)sqlite3_malloc(nZip);
    if( aZip==0 ){
      sqlite3_result_error_nomem(pCtx);
    }else{
      memcpy(aZip, p->body.a, p->body.n);
      memcpy(&aZip[p->body.n], p->cds.a, p->cds.n);
      zipfileSerializeEOCD(&eocd, &aZip[p->body.n + p->cds.n]);
      sqlite3_result_blob(pCtx, aZip, nZip, zipfileFree);
    }
  }

  sqlite3_free(p->body.a);
  sqlite3_free(p->cds.a);
}


Changes to test/zipfile.test.

419
420
421
422
423
424
425








426
427
428
429
430
431
432
433
...
434
435
436
437
438
439
440
441






442





















443
444
445
446
    }
  } [list {*}{
    test_unzip/a.txt 946684800
    test_unzip/b.txt 1000000000 
    test_unzip/c.txt 1111111000 
  }]









  do_test 6.1 {
    forcedelete test_unzip
    file mkdir test_unzip
    exec unzip -d test_unzip test2.zip

    db eval {
      SELECT name, mtime 
      FROM fsdir('test_unzip') WHERE name!='test_unzip'
................................................................................
      ORDER BY name
    }
  } [list {*}{
    test_unzip/a.txt 946684800
    test_unzip/b.txt 1000000000 
    test_unzip/c.txt 1111111000 
  }]
}






}























finish_test








>
>
>
>
>
>
>
>
|







 







|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
    }
  } [list {*}{
    test_unzip/a.txt 946684800
    test_unzip/b.txt 1000000000 
    test_unzip/c.txt 1111111000 
  }]

  do_execsql_test 6.1 {
    SELECT name, mtime, data FROM zipfile('test1.zip')
  } {
    a.txt 946684800   abc
    b.txt 1000000000  abc
    c.txt 1111111000  abc
  }

  do_test 6.2 {
    forcedelete test_unzip
    file mkdir test_unzip
    exec unzip -d test_unzip test2.zip

    db eval {
      SELECT name, mtime 
      FROM fsdir('test_unzip') WHERE name!='test_unzip'
................................................................................
      ORDER BY name
    }
  } [list {*}{
    test_unzip/a.txt 946684800
    test_unzip/b.txt 1000000000 
    test_unzip/c.txt 1111111000 
  }]

  do_execsql_test 6.3 {
    SELECT name, mtime, data FROM zipfile('test2.zip')
  } {
    a.txt 946684800   abc
    b.txt 1000000000  abc
    c.txt 1111111000  abc
  }
}
}

#-------------------------------------------------------------------------
forcedelete test.zip
do_test 7.0 {
  execsql {
    WITH c(name,data) AS (
        SELECT '1', randomblob(1000000) UNION ALL
        SELECT '2', randomblob(1000000) UNION ALL
        SELECT '3', randomblob(1000000) 
    )
    SELECT writefile('test.zip', zipfile(name, data) ) FROM c;
  }

  list [catch {
    db eval { SELECT name, data FROM zipfile('test.zip') } {
      if {$name==2} { close [open test.zip w+] }
    }
  } msg] $msg
} {1 {error in fread()}}


finish_test

Changes to test/zipfilefault.test.

52
53
54
55
56
57
58
59
60
61
62
63













64
65
66
67
reset_db
load_static_extension db zipfile
do_execsql_test 3.0 {
  CREATE VIRTUAL TABLE setup USING zipfile('test.zip');
  INSERT INTO setup(name, data) VALUES('a.txt', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
}

do_faultsim_test 2 -faults oom* -body {
  execsql { SELECT name,data FROM zipfile('test.zip') }
} -test {
  faultsim_test_result {0 {a.txt aaaaaaaaaaaaaaaaaaaaaaaaaaaa}} 
}















finish_test








|




>
>
>
>
>
>
>
>
>
>
>
>
>




52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
reset_db
load_static_extension db zipfile
do_execsql_test 3.0 {
  CREATE VIRTUAL TABLE setup USING zipfile('test.zip');
  INSERT INTO setup(name, data) VALUES('a.txt', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
}

do_faultsim_test 3 -faults oom* -body {
  execsql { SELECT name,data FROM zipfile('test.zip') }
} -test {
  faultsim_test_result {0 {a.txt aaaaaaaaaaaaaaaaaaaaaaaaaaaa}} 
}

do_faultsim_test 4 -faults oom* -body {
  execsql {
    WITH c(n, d) AS (
      SELECT 1, 'aaaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb'
    )
    SELECT name, data FROM zipfile(
      (SELECT zipfile(n, d) FROM c)
    );
  }
} -test {
  faultsim_test_result {0 {1 aaaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb}}
}


finish_test