1--TEST--
2Trying to parse a file that is too large (over 4GB)
3--EXTENSIONS--
4tidy
5--SKIPIF--
6<?php
7if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
8if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
9if (getenv("SKIP_ASAN")) die("skip too big for asan");
10if (getenv("GITHUB_ACTIONS")) die("skip potentially crashes on GitHub actions");
11?>
12--CONFLICTS--
13all
14--INI--
15memory_limit="5G"
16--FILE--
17<?php
18
19$path = __DIR__ . '/too_large_test.html';
20$file = fopen($path, 'w+');
21
22// Write over 4GB
23const MIN_FILE_SIZE = 4_294_967_295;
24
25var_dump(fseek($file, MIN_FILE_SIZE+10));
26$s = str_repeat("a", 10);
27$bytes_written = fwrite($file, $s);
28if ($bytes_written === false) {
29    echo "Didn't write bytes\n";
30}
31
32$tidy = new tidy;
33try {
34    var_dump($tidy->parseFile($path));
35} catch (\Throwable $e) {
36    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
37}
38
39try {
40    var_dump(tidy_parse_file($path));
41} catch (\Throwable $e) {
42    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
43}
44
45try {
46    $tidy = new tidy($path);
47} catch (\Throwable $e) {
48    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
49}
50
51try {
52    tidy_repair_file($path);
53} catch (\Throwable $e) {
54    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
55}
56?>
57--CLEAN--
58<?php
59$path = __DIR__ . '/too_large_test.html';
60unlink($path);
61?>
62--EXPECT--
63int(0)
64ValueError: File content is too long
65ValueError: File content is too long
66ValueError: File content is too long
67ValueError: tidy_repair_file(): Argument #1 ($filename) File content is too long
68