ee7752a
diff -up db-5.3.21/src/env/env_region.c.zero-region db-5.3.21/src/env/env_region.c
ee7752a
--- db-5.3.21/src/env/env_region.c.zero-region	2012-05-11 19:57:53.000000000 +0200
ee7752a
+++ db-5.3.21/src/env/env_region.c	2017-09-06 08:50:45.310276385 +0200
ee7752a
@@ -1060,6 +1060,7 @@ __env_region_attach(env, infop, init, ma
ee7752a
 	REGION *rp;
ee7752a
 	int ret;
ee7752a
 	char buf[sizeof(DB_REGION_FMT) + 20];
ee7752a
+	struct stat st;
ee7752a
 
ee7752a
 	/*
ee7752a
 	 * Find or create a REGION structure for this region.  If we create
ee7752a
@@ -1090,6 +1091,14 @@ __env_region_attach(env, infop, init, ma
ee7752a
 	if ((ret = __env_sys_attach(env, infop, rp)) != 0)
ee7752a
 		goto err;
ee7752a
 
ee7752a
+        /* Check the size of the underlying file */
ee7752a
+        if (infop->fhp != NULL && F_ISSET(infop->fhp, DB_FH_OPENED) &&
ee7752a
+            infop->fhp->fd != -1 && fstat(infop->fhp->fd, &st) != -1 &&
ee7752a
+            st.st_size == 0) {
ee7752a
+            ret = DB_RUNRECOVERY;
ee7752a
+            goto err;
ee7752a
+        }
ee7752a
+
ee7752a
 	/*
ee7752a
 	 * Fault the pages into memory.  Note, do this BEFORE we initialize
ee7752a
 	 * anything because we're writing pages in created regions, not just
ee7752a
diff -up db-5.3.21/src/os/os_map.c.zero-region db-5.3.21/src/os/os_map.c
ee7752a
--- db-5.3.21/src/os/os_map.c.zero-region	2012-05-11 19:57:54.000000000 +0200
ee7752a
+++ db-5.3.21/src/os/os_map.c	2017-09-06 08:49:39.144546552 +0200
ee7752a
@@ -265,6 +265,9 @@ __os_detach(env, infop, destroy)
ee7752a
 	dbenv = env->dbenv;
ee7752a
 
ee7752a
 	rp = infop->rp;
ee7752a
+	/* Do not touch the region information if it no longer exists */
ee7752a
+	if (rp == NULL)
ee7752a
+	    return EINVAL;
ee7752a
 
ee7752a
 	/* If the user replaced the unmap call, call through their interface. */
ee7752a
 	if (DB_GLOBAL(j_region_unmap) != NULL)