Page MenuHomePhabricator

Year 10,000 problem
Open, LowestPublicFeature

Description

Author: anminh2008

Description:
The MediaWiki software does not supprt 5+ digits year, make it vulnerable to the http://en.wikipedia.org/wiki/Year_10,000_problem and year 10^n (where n is a natural number) problem


Version: 1.23.0
Severity: enhancement

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:58 PM
bzimport set Reference to bz30148.
bzimport added a subscriber: Unknown Object (MLST).

Bumping back down, not a blocker... This isn't really a issue, This can be fixed in a "few" years closer to event if its a issue then.

anminh2008 wrote:

Fix it before it is too late to fix! FIX ONCE FOR FOREVER!!!!!!!

WONTFIXing this, we will most likley not do this, or if we do it won't be for ages since their isn't a pressing need for it.

But if you do desire feel free to work on it and send us patches for it.

anminh2008 wrote:

Are you ad your succesors choose to not fix it even after the Dark Era!?

We can reopen this sometime around the 10th millennium.

anminh2008 wrote:

If your math formulas involve future times, like astronomical calculation, you MUST fix it right now.

Well now you're talking about different things...which sort of failures are you talking about? Stuff involving math operations on dates probably is a ParserFunction bug. Problems with date autolinking are MW core, but we're not expanding that to non-English and might even remove it from English too making it a non-bug. Stuff relating to tracking of revision timestamps and the like won't be an issue for ~8000 more years.

Causing exceptions in production.

Example: https://en.wikipedia.org/wiki/Special:FeedItem/featured/2014021000000/en

2014-02-01 17:38:26 mw1036 enwiki: [2ec80205] /wiki/Special:FeedItem/featured/2014021000000/en Exception from line 1131 of /usr/local/apache/common-local/php-1.23wmf11/languages/Language.php: Language::sprintfDate: The timestamp 657911014000000 should have 14 characters
#0 /usr/local/apache/common-local/php-1.23wmf11/languages/Language.php(2045): Language->sprintfDate('j F Y', '657911014000000')
#1 /usr/local/apache/common-local/php-1.23wmf11/extensions/FeaturedFeeds/SpecialFeedItem.php(52): Language->date(2014020979200)
#2 /usr/local/apache/common-local/php-1.23wmf11/includes/specialpage/SpecialPage.php(374): SpecialFeedItem->execute('featured/201402...')
#3 /usr/local/apache/common-local/php-1.23wmf11/includes/SpecialPageFactory.php(487): SpecialPage->run('featured/201402...')
#4 /usr/local/apache/common-local/php-1.23wmf11/includes/Wiki.php(298): SpecialPageFactory::executePath(Object(Title), Object(RequestContext))
#5 /usr/local/apache/common-local/php-1.23wmf11/includes/Wiki.php(599): MediaWiki->performRequest()
#6 /usr/local/apache/common-local/php-1.23wmf11/includes/Wiki.php(460): MediaWiki->main()
#7 /usr/local/apache/common-local/php-1.23wmf11/index.php(49): MediaWiki->run()
#8 /usr/local/apache/common-local/w/index.php(3): require('/usr/local/apac...')
#9 {main}

Language::date depends on Language::sprintfDate, which does not support TS_MW values longer than 15 characters, but MWTimestamp::getTimestamp( TS_MW ) is liable to generate 15-character values.

$ts = wfTimestamp( TS_MW, 253402300800 )
$wgContLang->date( $ts );

[b4a5f86b] [no req] Exception from line 1131 of /a/common/php-1.23wmf11/languages/Language.php: Language::sprintfDate: The timestamp should have 14 characters
Backtrace:
#0 /a/common/php-1.23wmf11/languages/Language.php(2045): Language->sprintfDate(string, boolean)
#1 /a/common/php-1.23wmf11/maintenance/eval.php(71) : eval()'d code(1): Language->date(string)
#2 /a/common/php-1.23wmf11/maintenance/eval.php(71): eval()
#3 /a/common/multiversion/MWScript.php(97): require_once(string)
#4 {main}

The immediate fix for FeaturedFeeds is to reject feed timestamps set so far in the future as invalid.

The longer-term fix is to make the handling of >14 character timestamps consistent across MWTimestamp and Language::sprintfDate, either by making MWTimestamp decline to represent dates beyond 10000-01-01 using TS_MW format, or by making Language::sprintfDate handle TS_MW values longer than 14 characters.

(In reply to comment #8)

https://en.wikipedia.org/wiki/Special:FeedItem/featured/2014021000000/en
The immediate fix for FeaturedFeeds is to reject feed timestamps set so far
in the future as invalid.

(Done in Gerrit change I8a600d37a.)

As for handling these in sprintfDate, I'm reluctant to make any changes until PHP's DateTime also supports years > 9999 because we could only provide partial support without that.

I just wanted to add a few points that may be of interest to someone.

(1) This error may become more common with wikidata and its time datatype. I was looking at some errors in XOWA log files for ca.wikipedia.org and discovered that Saint Nicholas (https://ca.wikipedia.org/wiki/Nicolau_de_Mira) shows up as having died in 2003. See https://ca.wikipedia.org/wiki/Categoria:Morts_el_2003 . He died in 343 A.D..

For those interested, here's the process:

+000000000343-12-06T00:00:00Z

  • Note that this date adds an extra 0 at the beginning. Presumably this is a bug related to dates with a year < 1000.
  • This differs from other recent years of death

: For example, Albert Einstein (www.wikidata.org/wiki/q937) has this as his P570
+00000001955-04-18T00:00:00Z

  • Module:Wikidata calls lang:formatDate("Y", string.sub(d, 9, 18))

: This effectively becomes {{#time:Y|00343-12-0}} which generates 2003 (see note (2) below for more info)

(2) Any 5 digit year appears to produce a 4 digit year using the following method: "200" + 5th digit

5 digit years

{{#time:Y-m-d|00002-4-5}}<br/> -> 2002
{{#time:Y-m-d|54321-4-5}}<br/> -> 2001
{{#time:Y-m-d|12345-4-5}}<br/> -> 2005
{{#time:Y-m-d|55555-4-5}}<br/> -> 2005

(3) 6+ digit years are basically random, depending on what the last 4 digits are. I've gotten these type of results: current year; "19"+last_2_digits; "200"+last_digit; random substrings in the string; invalid time

You can start with these examples, and then try reversing them, or inputting random numbers

6-14 digit years

{{#time:Y-m-d|12345-4-5}}<br/>
{{#time:Y-m-d|123456-4-5}}<br/>
{{#time:Y-m-d|1234567-4-5}}<br/>
{{#time:Y-m-d|12345678-4-5}}<br/>
{{#time:Y-m-d|123456789-4-5}}<br/>
{{#time:Y-m-d|1234567890-4-5}}<br/>
{{#time:Y-m-d|12345678901-4-5}}<br/>
{{#time:Y-m-d|123456789012-4-5}}<br/>
{{#time:Y-m-d|1234567890123-4-5}}<br/>
{{#time:Y-m-d|12345678901234-4-5}}<br/>

DannyS712 lowered the priority of this task from Low to Lowest.Jul 5 2021, 5:22 PM
DannyS712 subscribed.

(we have thousands of years before this will be important to address)

Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 11:02 AM

Unfortunately this actually poses a problem in the common case where someone decides to block an user until 9999-12-31 23:59:59 instead of using the infinite expiry. The block log then breaks for every user that has a timezone preference whose offset is higher than the server timezone.

Change 768173 had a related patch set uploaded (by TK-999; author: TK-999):

[mediawiki/core@master] Language: Don't generate local dates in the year 10000

https://gerrit.wikimedia.org/r/768173

Unfortunately this actually poses a problem in the common case where someone decides to block an user until 9999-12-31 23:59:59 instead of using the infinite expiry. The block log then breaks for every user that has a timezone preference whose offset is higher than the server timezone.

Do you have an example link?

Unfortunately this actually poses a problem in the common case where someone decides to block an user until 9999-12-31 23:59:59 instead of using the infinite expiry. The block log then breaks for every user that has a timezone preference whose offset is higher than the server timezone.

Do you have an example link?

https://timelayers.fandom.com/wiki/Special:Log/block is one, specifically the entry with an expiry of 23:59, 31 December 9999. With the default timezone preference, the page loads fine. Set it to anything UTC+ and the page breaks :)

And the full stacktrace:

MWException from line 1177 of /languages/Language.php: Language::sprintfDate: The timestamp 100000101005959 should have 14 characters
	#0 /languages/Language.php(2451): Language->sprintfDate(string, string)
	#1 /languages/Language.php(2520): Language->internalUserTimeAndDate(string, string, User, array)
	#2 /languages/Language.php(4138): Language->userTimeAndDate(integer, User)
	#3 /includes/logging/BlockLogFormatter.php(63): Language->translateBlockExpiry(string, User, string)
	#4 /includes/logging/LogFormatter.php(465): BlockLogFormatter->getMessageParameters()
	#5 /includes/logging/LogFormatter.php(440): LogFormatter->getActionMessage()
	#6 /includes/logging/LogEventsList.php(397): LogFormatter->getActionText()
	#7 /includes/logging/LogPager.php(389): LogEventsList->logLine(stdClass)
	#8 /includes/pager/IndexPager.php(490): LogPager->formatRow(stdClass)
	#9 /includes/specials/SpecialLog.php(249): IndexPager->getBody()
	#10 /includes/specials/SpecialLog.php(139): SpecialLog->show(FormOptions, array)
	#11 /includes/specialpage/SpecialPage.php(569): SpecialLog->execute(string)
	#12 /includes/specialpage/SpecialPageFactory.php(558): SpecialPage->run(string)
	#13 /includes/MediaWiki.php(288): MediaWiki\Special\SpecialPageFactory->executePath(Title, RequestContext)
	#14 /includes/MediaWiki.php(870): MediaWiki->performRequest()
	#15 /includes/MediaWiki.php(520): MediaWiki->main()
	#16 /index.php(42): MediaWiki->run()
	#17 {main}

Change 768173 merged by jenkins-bot:

[mediawiki/core@master] Language: Don't generate local dates in the year 10000

https://gerrit.wikimedia.org/r/768173