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