diff --git a/Storage/Hashed/Index.hs b/Storage/Hashed/Index.hs
--- a/Storage/Hashed/Index.hs
+++ b/Storage/Hashed/Index.hs
@@ -152,7 +152,7 @@
         (dsc_fp, dsc_start, dsc_len) = toForeignPtr dsc
     withForeignPtr fp $ \p ->
         withForeignPtr dsc_fp $ \dsc_p ->
-            do pokeByteOff p (off + off_dsclen) dsc_len
+            do pokeByteOff p (off + off_dsclen) (xlate32 $ fromIntegral dsc_len :: Int32)
                memcpy (plusPtr p $ off + off_dsc)
                       (plusPtr dsc_p dsc_start)
                       (fromIntegral dsc_len)
@@ -206,11 +206,12 @@
 mmapIndex :: forall a. FilePath -> Int -> IO (ForeignPtr a, Int)
 mmapIndex indexpath req_size = do
   exist <- doesFileExist indexpath
-  act_size <- if exist then fileSize `fmap` getFileStatus indexpath
-                       else return 0
-  let size :: Int
-      size = fromIntegral $
-                 if req_size > 0 then fromIntegral req_size else act_size
+  act_size <- fromIntegral `fmap` if exist then fileSize `fmap` getFileStatus indexpath
+                                           else return 0
+  let size = case req_size > 0 of
+        True -> req_size
+        False | act_size >= size_magic -> act_size - size_magic
+              | otherwise -> 0
   case size of
     0 -> return (castForeignPtr nullForeignPtr, size)
     _ -> do (x, _) <- mmapFileForeignPtr indexpath
diff --git a/hashed-storage.cabal b/hashed-storage.cabal
--- a/hashed-storage.cabal
+++ b/hashed-storage.cabal
@@ -1,5 +1,5 @@
 name:          hashed-storage
-version:       0.4.7
+version:       0.4.8
 synopsis:      Hashed file storage support code.
 
 description:   Support code for reading and manipulating hashed file storage
