Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13600 closed (fixed)

OverflowError not caught in django.views.static.serve

Reported by: KostikVento 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: UI/UX:

Description (last modified by Alex)

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 SmileyChris 4 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 4 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by russellm

  • Resolution set to worksforme
  • Status changed from new to closed

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 follow-up: Changed 4 years ago by adamnelson

  • Component changed from Uncategorized to HTTP handling
  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Version changed from 1.1 to 1.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 Changed 4 years ago by adamnelson

BTW, this is on Ubuntu 10.04 with Python 2.6.5

comment:5 in reply to: ↑ 3 Changed 4 years ago by ramiro

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 Changed 4 years ago by adamnelson

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 Changed 4 years ago by adamnelson

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 Changed 4 years ago by adamnelson

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

Changed 4 years ago by SmileyChris

comment:9 Changed 4 years ago by SmileyChris

  • Has patch set
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:10 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from reopened to closed

(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 Changed 4 years ago by jezdez

(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).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.