Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ext/standard/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "php.h"
#include "base64.h"

#if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
#endif

/* {{{ base64 tables */
static const char base64_table[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
Expand Down Expand Up @@ -891,6 +895,12 @@ PHPAPI zend_string *php_base64_encode(const unsigned char *str, size_t length)
zend_string *result;

result = zend_string_safe_alloc(((length + 2) / 3), 4 * sizeof(char), 0, 0);

# if __has_feature(memory_sanitizer)
/* Clang 18 MSan does not instrument on AArch64. */
Copy link
Member

@iluuu1994 iluuu1994 Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not accurate. Instrumentation does happen, just not correctly. I believe it's some intrinsic calls in neon_base64_encode/neon_base64_decode that actually lack instrumentation. So, you should likely move these unpoisons there. It might also be nice to move the __msan_unpoison to zend_portability.h with a conditional macro so that we can avoid the constant #include and __has_feature(memory_sanitizer).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will try to move to zend_portability.h

__msan_unpoison(ZSTR_VAL(result), ZSTR_LEN(result));
# endif

p = (unsigned char *)ZSTR_VAL(result);

p = php_base64_encode_impl(str, length, p);
Expand All @@ -913,6 +923,11 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length

result = zend_string_alloc(length, 0);

# if __has_feature(memory_sanitizer)
/* Clang 18 MSan does not instrument on AArch64. */
__msan_unpoison(ZSTR_VAL(result), ZSTR_LEN(result));
# endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


if (!php_base64_decode_impl(str, length, (unsigned char*)ZSTR_VAL(result), &outl, strict)) {
zend_string_efree(result);
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ PHP_FUNCTION(usleep)
PHP_FUNCTION(time_nanosleep)
{
zend_long tv_sec, tv_nsec;
struct timespec php_req, php_rem;
struct timespec php_req, php_rem = {0};

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(tv_sec)
Expand Down
Loading