xref: /PHP-8.0/ext/gettext/tests/44938.phpt (revision 9fbffe44)
1--TEST--
2#44938: gettext functions crash with overlong strings
3--SKIPIF--
4<?php
5if (!extension_loaded("gettext")) {
6    die("skip\n");
7}
8--FILE--
9<?php
10$overflown = str_repeat('C', 8476509);
11$msgid     = "msgid";
12$domain    = "domain";
13$category  = "cat";
14
15try {
16    bindtextdomain($overflown, 'path');
17} catch (ValueError $exception) {
18    echo $exception->getMessage() . "\n";
19}
20
21try {
22    dngettext($overflown, $msgid, $msgid, 1);
23} catch (ValueError $exception) {
24    echo $exception->getMessage() . "\n";
25}
26
27try {
28    dngettext($domain, $overflown, $msgid, 1);
29} catch (ValueError $exception) {
30    echo $exception->getMessage() . "\n";
31}
32
33try {
34    dngettext($domain, $msgid, $overflown, 1);
35} catch (ValueError $exception) {
36    echo $exception->getMessage() . "\n";
37}
38
39try {
40    gettext($overflown);
41} catch (ValueError $exception) {
42    echo $exception->getMessage() . "\n";
43}
44
45try {
46    ngettext($overflown, $msgid, -1);
47} catch (ValueError $exception) {
48    echo $exception->getMessage() . "\n";
49}
50
51try {
52    ngettext($msgid, $overflown, -1);
53} catch (ValueError $exception) {
54    echo $exception->getMessage() . "\n";
55}
56
57try {
58    dcgettext($overflown, $msgid, -1);
59} catch (ValueError $exception) {
60    echo $exception->getMessage() . "\n";
61}
62
63try {
64    dcgettext($domain, $overflown, -1);
65} catch (ValueError $exception) {
66    echo $exception->getMessage() . "\n";
67}
68
69try {
70    dcngettext($overflown, $msgid, $msgid, -1, -1);
71} catch (ValueError $exception) {
72    echo $exception->getMessage() . "\n";
73}
74
75try {
76    dcngettext($domain, $overflown, $msgid, -1, -1);
77} catch (ValueError $exception) {
78    echo $exception->getMessage() . "\n";
79}
80
81try {
82    dcngettext($domain, $msgid, $overflown, -1, -1);
83} catch (ValueError $exception) {
84    echo $exception->getMessage() . "\n";
85}
86
87try {
88    dgettext($overflown, $msgid);
89} catch (ValueError $exception) {
90    echo $exception->getMessage() . "\n";
91}
92
93try {
94    dgettext($domain, $overflown);
95} catch (ValueError $exception) {
96    echo $exception->getMessage() . "\n";
97}
98
99try {
100    textdomain($overflown);
101} catch (ValueError $exception) {
102    echo $exception->getMessage() . "\n";
103}
104
105?>
106--EXPECT--
107bindtextdomain(): Argument #1 ($domain) is too long
108dngettext(): Argument #1 ($domain) is too long
109dngettext(): Argument #2 ($singular) is too long
110dngettext(): Argument #3 ($plural) is too long
111gettext(): Argument #1 ($message) is too long
112ngettext(): Argument #1 ($singular) is too long
113ngettext(): Argument #2 ($plural) is too long
114dcgettext(): Argument #1 ($domain) is too long
115dcgettext(): Argument #2 ($message) is too long
116dcngettext(): Argument #1 ($domain) is too long
117dcngettext(): Argument #2 ($singular) is too long
118dcngettext(): Argument #3 ($plural) is too long
119dgettext(): Argument #1 ($domain) is too long
120dgettext(): Argument #2 ($message) is too long
121textdomain(): Argument #1 ($domain) is too long
122