From: Howard Chu Date: Mon, 30 Jun 2014 11:41:50 +0000 (-0700) Subject: ITS#7886 fix mdb_copy write size X-Git-Tag: OPENLDAP_REL_ENG_2_4_40~127^2~20 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b09e46904c1c059bd5086243e3915b6be510e57d;p=openldap ITS#7886 fix mdb_copy write size Don't try to write past end of file --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index c5311fab32..750c2bb161 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -4505,7 +4505,23 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd) if (rc) goto leave; - wsize = txn->mt_next_pgno * env->me_psize - wsize; + w2 = txn->mt_next_pgno * env->me_psize; +#ifdef WIN32 + { + LARGE_INTEGER fsize; + GetFileSizeEx(env->me_fd, &fsize); + if (w2 > fsize.QuadPart) + w2 = fsize.QuadPart; + } +#else + { + struct stat st; + fstat(env->me_fd, &st); + if (w2 > (size_t)st.st_size) + w2 = st.st_size; + } +#endif + wsize = w2 - wsize; while (wsize > 0) { if (wsize > MAX_WRITE) w2 = MAX_WRITE;