Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#13600 closed (fixed)

OverflowError not caught in django.views.static.serve

Reported by: Konstantin Hlyzov Owned by: nobody
Component: HTTP handling Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex Gaynor)

I noticed that sometimes I get an "OverflowError: mktime argument out of range" error in django.views.static.serve, when a request is made with a strange date, say, request.META contents something like {'HTTP_IF_MODIFIED_SINCE': 'Mon, 28 May 3121 28:25:26 GMT'}.

Python docs say on this that the exceptions raised in mktime are either ValueError (if caught in Python layer) or OverflowError (if caught in C layer).

I suppose it could be fixed with replacing the third endmost line in django.views.static.was_modified_since from actual

    except (AttributeError, ValueError):

to

    except (AttributeError, ValueError, OverflowError):

Probably, there has been some reason not to catch OverflowErrors, then sorry.

Attachments (1)

13600.diff (1.3 KB ) - added by Chris Beaven 14 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 by Alex Gaynor, 14 years ago

Description: modified (diff)

comment:2 by Russell Keith-Magee, 14 years ago

Resolution: worksforme
Status: newclosed

I can't reproduce the problem you describe -- using Python 2.6, the date "Mon 28 May 3121 28:25:26" actually parses correctly as "Tue, 29 May 3121 04:25:26"; using Python 2.5, it raises a ValueError. (Both of these tests were running under Mac OSX).

Closing worksforme; If you can provide more specific reproduction instructions, please reopen.

comment:3 by Adam Nelson, 14 years ago

Component: UncategorizedHTTP handling
Resolution: worksforme
Status: closedreopened
Version: 1.11.2

I can reproduce it, and I've just seen it on live. Here is the relevant part of the stack trace.

http://gist.github.com/545597

comment:4 by Adam Nelson, 14 years ago

BTW, this is on Ubuntu 10.04 with Python 2.6.5

in reply to:  3 comment:5 by Ramiro Morales, 14 years ago

Replying to adamnelson:

I can reproduce it, and I've just seen it on live. Here is the relevant part of the stack trace.

http://gist.github.com/545597

Can you reproduce the error condition at will?. If so, could you paste the text version of the stack trace?. There is a button for that in the exception page generated by Django when running with DEBUG=True.

comment:6 by Adam Nelson, 14 years ago

Here is the text version:

Traceback (most recent call last):

  File "/var/www/yipit-env/lib/python2.6/site-packages/django/core/handlers/base.py", line 100, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/var/www/yipit-env/lib/python2.6/site-packages/staticfiles/views.py", line 32, in serve
    show_indexes=show_indexes)

  File "/var/www/yipit-env/lib/python2.6/site-packages/django/views/static.py", line 61, in serve
    statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):

  File "/var/www/yipit-env/lib/python2.6/site-packages/django/views/static.py", line 129, in was_modified_since
    header_mtime = mktime_tz(parsedate_tz(matches.group(1)))

  File "/usr/lib/python2.6/email/_parseaddr.py", line 146, in mktime_tz
    t = time.mktime(data[:8] + (0,))

OverflowError: mktime argument out of range

comment:7 by Adam Nelson, 14 years ago

Oops, thought you just wanted the stack trace in text. These are from a live site so these are from djangodberrorlog. I'll try to replicate myself.

comment:8 by Adam Nelson, 14 years ago

I've updated the gist with the reproducible version. The easiest way to replicate this is to use http://modifyheaders.mozdev.org/ and modify:

If-Modified-Since to Mon, 29 Jul 3121 29:24:25 GMT

by Chris Beaven, 14 years ago

Attachment: 13600.diff added

comment:9 by Chris Beaven, 14 years ago

Has patch: set
Triage Stage: UnreviewedReady for checkin

comment:10 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: reopenedclosed

(In [13870]) Fixed #12544 and #13600 -- Fixed static files serving view to catch invalid date from If-Modified-Since header. Thanks akaihola and SmileyChris for patches.

comment:11 by Jannis Leidel, 14 years ago

(In [13871]) Fixed #12544 and #13600 -- Fixed static files serving view to catch invalid date from If-Modified-Since header. Thanks akaihola and SmileyChris for patches.

Backport from trunk (r13870).

Note: See TracTickets for help on using tickets.
Back to Top