Skip to content

Commit fdd9018

Browse files
committed
Support uuencoding empty string
Cross checking implementations from other languages, empty strings are always allowed. PHP's output is peculiar due to it's insistence to encode a trailing \0, but otherwise sensible and does round-trip as expected.
1 parent e60f927 commit fdd9018

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static const func_info_t func_infos[] = {
213213
F1("base64_encode", MAY_BE_STRING),
214214
F1("password_hash", MAY_BE_STRING),
215215
F1("password_get_info", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
216-
F1("convert_uuencode", MAY_BE_FALSE | MAY_BE_STRING),
216+
F1("convert_uuencode", MAY_BE_STRING),
217217
F1("convert_uudecode", MAY_BE_FALSE | MAY_BE_STRING),
218218
F1("pow", MAY_BE_LONG | MAY_BE_DOUBLE | MAY_BE_OBJECT),
219219
F1("decbin", MAY_BE_STRING),

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ function stream_filter_register(string $filtername, string $classname): bool {}
14651465

14661466
/* uuencode.c */
14671467

1468-
function convert_uuencode(string $data): string|false {}
1468+
function convert_uuencode(string $data): string {}
14691469

14701470
function convert_uudecode(string $data): string|false {}
14711471

ext/standard/basic_functions_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 621176b0f79f4fcb833c6be568adb2070239cce1 */
2+
* Stub hash: 3c02183529eed2eb21d801ed2ba615deaf749b1d */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -2158,7 +2158,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_filter_register, 0, 2, _I
21582158
ZEND_ARG_TYPE_INFO(0, classname, IS_STRING, 0)
21592159
ZEND_END_ARG_INFO()
21602160

2161-
#define arginfo_convert_uuencode arginfo_hex2bin
2161+
#define arginfo_convert_uuencode arginfo_bin2hex
21622162

21632163
#define arginfo_convert_uudecode arginfo_hex2bin
21642164

ext/standard/tests/strings/uuencode.phpt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ uuencode family tests
33
--FILE--
44
<?php
55

6-
var_dump(convert_uuencode(""));
7-
var_dump(convert_uudecode(""));
6+
var_dump($enc = convert_uuencode(""));
7+
var_dump(convert_uudecode($enc));
88
var_dump($enc = convert_uuencode("~!@#$%^&*()_}{POIUYTREWQQSDFGHJKL:<MNBVCXZ"));
99
var_dump(convert_uudecode("!@#$%^YUGFDFGHJKLUYTFBNMLOYT"));
1010
var_dump(convert_uudecode($enc));
1111
var_dump($enc = convert_uuencode("not very sophisticated"));
1212
var_dump(convert_uudecode($enc));
13+
var_dump(convert_uudecode(""));
1314
var_dump(convert_uudecode(substr($enc, 0, -10)));
1415

1516
echo "Done\n";
1617
?>
1718
--EXPECTF--
18-
bool(false)
19-
bool(false)
19+
string(2) "`
20+
"
21+
string(0) ""
2022
string(60) "J?B%`(R0E7B8J*"E??7M03TE5651215=145-$1D=(2DM,.CQ-3D)60UA:
2123
`
2224
"
@@ -27,6 +29,9 @@ string(36) "6;F]T('9E<GD@<V]P:&ES=&EC871E9```
2729
"
2830
string(22) "not very sophisticated"
2931

32+
Warning: convert_uudecode(): Argument #1 ($data) is not a valid uuencoded string in %s on line %d
33+
bool(false)
34+
3035
Warning: convert_uudecode(): Argument #1 ($data) is not a valid uuencoded string in %s on line %d
3136
bool(false)
3237
Done

ext/standard/uuencode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ PHPAPI zend_string *php_uudecode(const char *src, size_t src_len) /* {{{ */
133133
const char *s, *e, *ee;
134134
zend_string *dest;
135135

136+
if (src_len == 0) {
137+
return NULL;
138+
}
139+
136140
dest = zend_string_alloc((size_t) ceil(src_len * 0.75), 0);
137141
p = ZSTR_VAL(dest);
138142
s = src;
@@ -204,7 +208,6 @@ PHP_FUNCTION(convert_uuencode)
204208
ZEND_PARSE_PARAMETERS_START(1, 1)
205209
Z_PARAM_STR(src)
206210
ZEND_PARSE_PARAMETERS_END();
207-
if (ZSTR_LEN(src) < 1) { RETURN_FALSE; }
208211

209212
RETURN_STR(php_uuencode(ZSTR_VAL(src), ZSTR_LEN(src)));
210213
}
@@ -219,7 +222,6 @@ PHP_FUNCTION(convert_uudecode)
219222
ZEND_PARSE_PARAMETERS_START(1, 1)
220223
Z_PARAM_STR(src)
221224
ZEND_PARSE_PARAMETERS_END();
222-
if (ZSTR_LEN(src) < 1) { RETURN_FALSE; }
223225

224226
if ((dest = php_uudecode(ZSTR_VAL(src), ZSTR_LEN(src))) == NULL) {
225227
php_error_docref(NULL, E_WARNING, "Argument #1 ($data) is not a valid uuencoded string");

0 commit comments

Comments
 (0)