aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2015-01-12 08:11:07 -0700
committerBen Johnson <benbjohnson@yahoo.com>2015-01-12 08:11:07 -0700
commit1c6f04b302d7721bb098f4960fceabfb1b5f3466 (patch)
treeff980f01722b8ec873113206dec419ffa4546534
parentMerge pull request #281 from tgulacsi/master (diff)
parentAdd check for max mmap size. (diff)
downloaddedo-1c6f04b302d7721bb098f4960fceabfb1b5f3466.tar.gz
dedo-1c6f04b302d7721bb098f4960fceabfb1b5f3466.tar.xz
Merge pull request #282 from benbjohnson/max-mmap-check
Add check for max mmap size.
-rw-r--r--db.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/db.go b/db.go
index 6c45736..ad27176 100644
--- a/db.go
+++ b/db.go
@@ -162,16 +162,6 @@ func (db *DB) mmap(minsz int) error {
db.mmaplock.Lock()
defer db.mmaplock.Unlock()
- // Dereference all mmap references before unmapping.
- if db.rwtx != nil {
- db.rwtx.root.dereference()
- }
-
- // Unmap existing data before continuing.
- if err := db.munmap(); err != nil {
- return err
- }
-
info, err := db.file.Stat()
if err != nil {
return fmt.Errorf("mmap stat error: %s", err)
@@ -186,6 +176,21 @@ func (db *DB) mmap(minsz int) error {
}
size = db.mmapSize(size)
+ // Verify the map size is not above the maximum allowed.
+ if size > maxMapSize {
+ return fmt.Errorf("mmap too large")
+ }
+
+ // Dereference all mmap references before unmapping.
+ if db.rwtx != nil {
+ db.rwtx.root.dereference()
+ }
+
+ // Unmap existing data before continuing.
+ if err := db.munmap(); err != nil {
+ return err
+ }
+
// Memory-map the data file as a byte slice.
if err := mmap(db, size); err != nil {
return err