Skip to content

Commit bb3946a

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78808: [LMDB] MDB_MAP_FULL: Environment mapsize limit reached
2 parents d492766 + f4aa086 commit bb3946a

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

ext/dba/dba_lmdb.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ DBA_OPEN_FUNC(lmdb)
4141
MDB_env *env;
4242
MDB_txn *txn;
4343
int rc, mode = 0644, flags = MDB_NOSUBDIR;
44+
zend_long mapsize = 0;
4445

4546
if(info->argc > 0) {
4647
mode = zval_get_long(&info->argv[0]);
4748

49+
if (info->argc > 1) {
50+
mapsize = zval_get_long(&info->argv[1]);
51+
if (mapsize < 0) {
52+
*error = "mapsize must be greater than or equal to zero";
53+
return FAILURE;
54+
}
55+
}
4856
/* TODO implement handling of the additional flags. */
4957
}
5058

@@ -54,6 +62,14 @@ DBA_OPEN_FUNC(lmdb)
5462
return FAILURE;
5563
}
5664

65+
if (mapsize > 0) {
66+
rc = mdb_env_set_mapsize(env, (size_t) mapsize);
67+
if (rc) {
68+
*error = mdb_strerror(rc);
69+
return FAILURE;
70+
}
71+
}
72+
5773
rc = mdb_env_open(env, info->path, flags, mode);
5874
if (rc) {
5975
*error = mdb_strerror(rc);

ext/dba/tests/bug78808.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #78808 ([LMDB] MDB_MAP_FULL: Environment mapsize limit reached)
3+
--SKIPIF--
4+
<?php
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
$handler = 'lmdb';
7+
require_once __DIR__ .'/skipif.inc';
8+
?>
9+
--FILE--
10+
<?php
11+
$handler = 'lmdb';
12+
require_once __DIR__ .'/test.inc';
13+
$lmdb_h = dba_open($db_filename, 'c', 'lmdb', 0644, 5*1048576);
14+
for ($i = 0; $i < 50000; $i++) {
15+
dba_insert('key' . $i, 'value '. $i, $lmdb_h);
16+
}
17+
dba_close($lmdb_h);
18+
echo "done\n";
19+
?>
20+
--EXPECT--
21+
done
22+
--CLEAN--
23+
<?php
24+
require_once dirname(__FILE__) .'/clean.inc';
25+
?>

0 commit comments

Comments
 (0)