2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include <folly/portability/GTest.h>
19 #include "hphp/runtime/base/array-init.h"
20 #include "hphp/runtime/base/exceptions.h"
21 #include "hphp/runtime/base/memory-manager.h"
22 #include "hphp/runtime/base/program-functions.h"
23 #include "hphp/runtime/base/req-vector.h"
24 #include "hphp/runtime/base/surprise-flags.h"
25 #include "hphp/runtime/ext/json/JSON_parser.h"
26 #include "hphp/runtime/ext/json/ext_json.h"
30 void test_json(const char* json
) {
31 auto old_limit
= tl_heap
->getMemoryLimit();
32 tl_heap
->setMemoryLimit(tl_heap
->getStatsCopy().usage() + 0x10000);
34 req::vector
<Variant
> buf
;
35 ASSERT_LE(tl_heap
->getStatsCopy().usage(), tl_heap
->getMemoryLimit());
36 ASSERT_FALSE(getSurpriseFlag(MemExceededFlag
));
37 auto len
= strlen(json
);
39 for (int i
= 0; i
< 100000; i
++) {
40 // call into SimpleParser
42 auto ok
= JSON_parser(z
, json
, len
, true, 0xffff,
45 ASSERT_FALSE(getSurpriseFlag(MemExceededFlag
));
48 } catch (RequestMemoryExceededException
& e
) {
52 tl_heap
->setMemoryLimit(old_limit
);
53 tl_heap
->resetCouldOOM();
56 TEST(JSON
, simple_packed_oom
) {
57 test_json("[\"a\",1,true,false,null]");
60 TEST(JSON
, simple_mixed_oom
) {
61 test_json("{\"a\":1,\"b\":2.3,\"3\":\"test\"}");