Use 64-bit arithmetic in the xRead() method of asyncRead. Fix for [94c04eaadb].

FossilOrigin-Name: ca3e41b0574cfd8d971c2be2114e58273a531970
diff --git a/ext/async/sqlite3async.c b/ext/async/sqlite3async.c
index 11a4761..0cfc7f6 100644
--- a/ext/async/sqlite3async.c
+++ b/ext/async/sqlite3async.c
@@ -668,8 +668,8 @@
   AsyncFileData *p = ((AsyncFile *)pFile)->pData;
   int rc = SQLITE_OK;
   sqlite3_int64 filesize;
-  int nRead;
   sqlite3_file *pBase = p->pBaseRead;
+  sqlite3_int64 iAmt64 = (sqlite3_int64)iAmt;
 
   /* Grab the write queue mutex for the duration of the call */
   async_mutex_enter(ASYNC_MUTEX_QUEUE);
@@ -683,11 +683,12 @@
   }
 
   if( pBase->pMethods ){
+    sqlite3_int64 nRead;
     rc = pBase->pMethods->xFileSize(pBase, &filesize);
     if( rc!=SQLITE_OK ){
       goto asyncread_out;
     }
-    nRead = (int)MIN(filesize - iOffset, iAmt);
+    nRead = MIN(filesize - iOffset, iAmt64);
     if( nRead>0 ){
       rc = pBase->pMethods->xRead(pBase, zOut, nRead, iOffset);
       ASYNC_TRACE(("READ %s %d bytes at %d\n", p->zName, nRead, iOffset));
@@ -703,14 +704,20 @@
         (pWrite->pFileData==p) ||
         (zName && pWrite->pFileData->zName==zName)
       )){
+        sqlite3_int64 nCopy;
+        sqlite3_int64 nByte64 = (sqlite3_int64)pWrite->nByte;
+
+        /* Set variable iBeginIn to the offset in buffer pWrite->zBuf[] from
+        ** which data should be copied. Set iBeginOut to the offset within
+        ** the output buffer to which data should be copied. If either of
+        ** these offsets is a negative number, set them to 0.
+        */
         sqlite3_int64 iBeginOut = (pWrite->iOffset-iOffset);
         sqlite3_int64 iBeginIn = -iBeginOut;
-        int nCopy;
-
         if( iBeginIn<0 ) iBeginIn = 0;
         if( iBeginOut<0 ) iBeginOut = 0;
-        nCopy = (int)MIN(pWrite->nByte-iBeginIn, iAmt-iBeginOut);
 
+        nCopy = MIN(nByte64-iBeginIn, iAmt64-iBeginOut);
         if( nCopy>0 ){
           memcpy(&((char *)zOut)[iBeginOut], &pWrite->zBuf[iBeginIn], nCopy);
           ASYNC_TRACE(("OVERREAD %d bytes at %d\n", nCopy, iBeginOut+iOffset));