Skip to content

Commit 8c5e254

Browse files
committed
Validate UTF-8 in scalar phongo_zval_to_bson_value path
The IS_STRING branch wrote the PHP string verbatim into the bson_value_t without checking that it was valid UTF-8, while the phongo_bson_append document-encoding path already validates. Match the existing pattern so that invalid UTF-8 is rejected with an exception in both code paths.
1 parent 535ebda commit 8c5e254

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/phongo_bson_encode.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@ bool phongo_zval_to_bson_value(zval* data, bson_value_t* value)
643643
return true;
644644

645645
case IS_STRING:
646+
if (!bson_utf8_validate(Z_STRVAL_P(data), Z_STRLEN_P(data), true)) {
647+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Detected invalid UTF-8 in string value");
648+
return false;
649+
}
650+
646651
value->value_type = BSON_TYPE_UTF8;
647652
value->value.v_utf8.len = Z_STRLEN_P(data);
648653

0 commit comments

Comments
 (0)