New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 693053 link

Starred by 5 users

Issue metadata

Status: Fixed
Owner:
Email to this user bounced
Closed: Feb 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

document.lastModified returns bogus date when Last-Modified HTTP header is malformed

Project Member Reported by alogvi...@yandex-team.ru, Feb 16 2017

Issue description

Chrome Version: 55.0.2883.91
OS: Found on Android, but other platforms are affected as well

What steps will reproduce the problem?
(1) Run the attached python script. It will start a local http server on port 9999.
(2) Open the URL "http://localhost:9999/"

What is the expected result?

Current date is displayed.

What happens instead?

"01/00/0000 00:00:00" is displayed.

The attached python script serves an HTML page which displays the value returned by "document.lastModified". The script also attaches a malformed "Last-Modified" HTTP header to the response.

Per HTML spec https://html.spec.whatwg.org/#dom-document-lastmodified , "If the last modification date and time are not known, the attribute must return the current date and time in the above format.". But the current behavior is that a bogus date "01/00/0000 00:00:00" is returned in release builds, and there is a renderer crash on DCHECK in debug builds in WTF::msToYear.

Absence of "Last-Modified" HTTP header yields the correct result: the current date is returned.

The problem is that in blink::Document::lastModified(), the header value is parsed into a double value (NaN when malformed) and then passed without validation to convertToLocalTime(): https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/dom/Document.cpp?dr=CSs&l=4670

The solution would probably be to validate the httpLastModified in Document::LastModified() (i.e. check that the resulting double value is not NaN) and return the current date, same as when httpLastModified is empty.

The problem is not reproduced in Firefox which returns the current date.
 
invalid_last_modified.py
677 bytes View Download
Project Member

Comment 1 by bugdroid1@chromium.org, Feb 16 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/de777ac871873450a4cb4b77c9b2fa7bdc3be990

commit de777ac871873450a4cb4b77c9b2fa7bdc3be990
Author: sigbjornf <sigbjornf@opera.com>
Date: Thu Feb 16 22:31:39 2017

document.lastModified: treat invalid dates like unknown ones.

If the value supplied via Last-Modified: is unparseable, treat the
modification date as unknown and return the current time (rather than
00-00-0000 00:00:00)

This aligns behavior with all other browsers.

R=foolip
BUG= 693053 

Review-Url: https://codereview.chromium.org/2698773005
Cr-Commit-Position: refs/heads/master@{#451123}

[modify] https://crrev.com/de777ac871873450a4cb4b77c9b2fa7bdc3be990/third_party/WebKit/LayoutTests/http/tests/misc/last-modified-parsing-expected.txt
[modify] https://crrev.com/de777ac871873450a4cb4b77c9b2fa7bdc3be990/third_party/WebKit/LayoutTests/http/tests/misc/last-modified-parsing.html
[modify] https://crrev.com/de777ac871873450a4cb4b77c9b2fa7bdc3be990/third_party/WebKit/LayoutTests/http/tests/resources/last-modified.php
[modify] https://crrev.com/de777ac871873450a4cb4b77c9b2fa7bdc3be990/third_party/WebKit/Source/core/dom/Document.cpp

Comment 2 by tkent@chromium.org, Feb 17 2017

Labels: Hotlist-Interop
Owner: sigbjo...@opera.com
Status: Assigned (was: Untriaged)

Comment 3 by sigbjo...@opera.com, Feb 17 2017

Status: Fixed (was: Assigned)
 Issue 696184  has been merged into this issue.
Cc: msrchandra@chromium.org
 Issue 672234  has been merged into this issue.

Sign in to add a comment