Skip to content

Commit 78defb0

Browse files
committed
pp_pack: unpack: Use 'uv' form, not 'uvchr'
Like previous commits, this converts a call to utf8n_to_uvchr() to use instead utf8_to_uv_flags(). And like previous commits, the previous code thought it was checking for failure and croaking, but was checking the wrong way so that it never could fail. With the new commit, it can fail. Also, the previous commit stored the result in an 'int', whose range can be significantly less than the code point returned. The value was truncated without notice. Now, I croak if the value got truncated. This code doesn't fully make sense to me, as this is for unpacking a 'c' format, which is supposed to be a signed 8-bit value, and what is getting stored is a full integer value
1 parent 9a463d3 commit 78defb0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pp_pack.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,10 +1239,21 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
12391239
int aint;
12401240
if (utf8) {
12411241
STRLEN retlen;
1242-
aint = utf8n_to_uvchr((U8 *) s, strend-s, &retlen,
1243-
ckWARN(WARN_UTF8) ? 0 : UTF8_ALLOW_ANY);
1244-
if (retlen == (STRLEN) -1)
1242+
UV auv;
1243+
if (! utf8_to_uv_flags((U8 *) s, (U8 *) strend,
1244+
&auv, &retlen,
1245+
(ckWARN(WARN_UTF8))
1246+
? 0
1247+
: UTF8_ALLOW_ANY))
1248+
{
1249+
croak("Malformed UTF-8 string in unpack");
1250+
}
1251+
1252+
aint = auv;
1253+
if ( (UV) aint != auv) {
12451254
croak("Malformed UTF-8 string in unpack");
1255+
}
1256+
12461257
s += retlen;
12471258
}
12481259
else {

0 commit comments

Comments
 (0)