Skip to content

ext/Intl: Fix IntlDateFormatter offset type validation#22533

Open
LamentXU123 wants to merge 3 commits into
php:masterfrom
LamentXU123:cast-intl
Open

ext/Intl: Fix IntlDateFormatter offset type validation#22533
LamentXU123 wants to merge 3 commits into
php:masterfrom
LamentXU123:cast-intl

Conversation

@LamentXU123

Copy link
Copy Markdown
Member

Now in IntlDateFormatter::parseToCalendar we verify if the offset is a int

 <?php
  $fmt = new IntlDateFormatter('en_GB');
  $fmt->setPattern('VV');

  $offset = 'offset';

  try {
      $fmt->parseToCalendar('America/Los_Angeles', $offset);
  } catch (TypeError $e) {
      echo $e->getMessage(), PHP_EOL;
  }
IntlDateFormatter::parseToCalendar(): Argument #2 ($offset) must be of type int, string given

reproduce here
However, in IntlDateFormatter::parse() and IntlDateFormatter::localtime() we silently accept offset that is not a int and turns it into 0

<?php
  $fmt = new IntlDateFormatter('en_GB');
  $fmt->setPattern('VV');

  $offset = 'offset';
  $fmt->parse('America/Los_Angeles', $offset);
  $fmt->localtime('America/Los_Angeles', $offset);

This will not throws an error, reproduce here

At least for consistence's sake, we should reject non-int offset in these functions (This also aligns with previous fixes about avoiding silently casting).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant