/ Check-in [0edad533]
Login

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

Overview
Comment:Fix the readfile() UDF so that it returns an empty BLOB, not an OOM error, when reading an empty file.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0edad5339e36d69aed9289bb3e60d35f9930386d76a62bb0194c4fdf420d16fb
User & Date: drh 2019-02-27 19:59:56
Context
2019-02-27
23:05
Enable the LIKE optimization when the ESCAPE keyword is present and the PRAGMA case_sensitive_like pragma is ON. check-in: 6ae4b8c5 user: drh tags: trunk
19:59
Fix the readfile() UDF so that it returns an empty BLOB, not an OOM error, when reading an empty file. check-in: 0edad533 user: drh tags: trunk
16:38
Add the "-returntype" option to the "db function" Tcl method. check-in: 789a492b user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/fileio.c.

   148    148     db = sqlite3_context_db_handle(ctx);
   149    149     mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
   150    150     if( nIn>mxBlob ){
   151    151       sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
   152    152       fclose(in);
   153    153       return;
   154    154     }
   155         -  pBuf = sqlite3_malloc64( nIn );
          155  +  pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
   156    156     if( pBuf==0 ){
   157    157       sqlite3_result_error_nomem(ctx);
   158    158       fclose(in);
   159    159       return;
   160    160     }
   161         -  if( 1==fread(pBuf, nIn, 1, in) ){
          161  +  if( nIn==fread(pBuf, 1, nIn, in) ){
   162    162       sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
   163    163     }else{
   164    164       sqlite3_result_error_code(ctx, SQLITE_IOERR);
   165    165       sqlite3_free(pBuf);
   166    166     }
   167    167     fclose(in);
   168    168   }