Skip to content

Change mbstring values from size_t to ptrdiff_t as that's what they return #5196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Feb 22, 2020

As this has emerged out of #5151 that this may be a bug.

Oniguruma is returning a ptrdiff_t but we were storing it in a size_t but a ptrdiff_t may be negative.

@Girgias Girgias requested a review from nikic February 22, 2020 01:20
@nikic
Copy link
Member

nikic commented Feb 23, 2020

I would suggest to use the actual OnigWhatever type here, even if it typedefs to ptrdiff_t.

@Girgias
Copy link
Member Author

Girgias commented Feb 23, 2020

I would suggest to use the actual OnigWhatever type here, even if it typedefs to ptrdiff_t.

Well there isn't really a typedef from what I saw:

beg and end are fetched from the MBREX(search_regs) which is defined as a OnigRegion as can be seen here:

struct _zend_mb_regex_globals {
	OnigEncoding default_mbctype;
	OnigEncoding current_mbctype;
	HashTable ht_rc;
	zval search_str;
	zval *search_str_val;
	size_t search_pos;
	php_mb_regex_t *search_re;
	OnigRegion *search_regs;
	OnigOptionType regex_default_options;
	OnigSyntaxType *regex_default_syntax;
};

(see: https://php-lxr.adamharvey.name/source/xref/master/ext/mbstring/php_mbregex.c#63)

And OnigRegion is a typedef to the re_registers struct which is as following:

struct re_registers {
  int  allocated;
  int  num_regs;
  int* beg;
  int* end;
  /* extended */
  OnigCaptureTreeNode* history_root;  /* capture history tree root */
};

(See https://github.com/kkos/oniguruma/blob/master/src/oniguruma.h#L652 and line 670)

And from what I saw in oniguruma.h all the typedefs are unsigned int or unsigned char

@nikic
Copy link
Member

nikic commented Feb 25, 2020

Thanks for the reference. In that case, shouldn't the type be int rather than ptrdiff_t?

@Girgias
Copy link
Member Author

Girgias commented Feb 26, 2020

Thanks for the reference. In that case, shouldn't the type be int rather than ptrdiff_t?

Indeed that would make more sense, I looked into it after you wanted me to change it to OnigSomething so I was trying to figure out what they were. :)

@php-pulls php-pulls closed this in c7094d8 Feb 26, 2020
@Girgias Girgias deleted the mbstring-size-t branch February 26, 2020 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants