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