From 7b10fdde0039cd79435a4ef128e882163d4ebd9a Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 4 Dec 2012 06:30:22 -0800 Subject: [PATCH] Fix mdb_env_copy Just write in 2^31 sized chunks --- libraries/liblmdb/mdb.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 4af49989cd..d1f957bcd8 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -3533,22 +3533,34 @@ mdb_env_copy(MDB_env *env, const char *path) ptr = env->me_map + wsize; wsize = txn->mt_next_pgno * env->me_psize - wsize; +#define MAX_WRITE 2147483648U #ifdef _WIN32 -#define MAX_UINT32 4294967295U while (wsize > 0) { DWORD len, w2; - if (wsize > MAX_UINT32) - w2 = MAX_UINT32 - env->me_psize + 1; /* write in pagesize chunks */ + if (wsize > MAX_WRITE) + w2 = MAX_WRITE; else w2 = wsize; rc = WriteFile(newfd, ptr, w2, &len, NULL); rc = (len == w2) ? MDB_SUCCESS : ErrCode(); if (rc) break; wsize -= w2; + ptr += w2; } #else - rc = write(newfd, ptr, wsize); - rc = (rc == (int)wsize) ? MDB_SUCCESS : ErrCode(); + while (wsize > 0) { + size_t w2; + ssize_t wres; + if (wsize > MAX_WRITE) + w2 = MAX_WRITE; + else + w2 = wsize; + wres = write(newfd, ptr, w2); + rc = (wres > 0) ? MDB_SUCCESS : ErrCode(); + if (rc) break; + wsize -= wres; + ptr += wres; + } #endif mdb_txn_abort(txn); -- 2.39.5