Edgewall Software

Ticket #7056 (closed defect: fixed)

Opened 8 months ago

Last modified 7 months ago

Large ticket numbers can trigger overflow error rather than "Ticket does not exist" on sqlite

Reported by: thatch Owned by: thatch
Priority: normal Milestone: 0.11
Component: ticket system Version: 0.11b2
Severity: normal Keywords:
Cc:

Description

Similar to #4794, viewing /ticket/99999999999999999999999999999999999999999999 would result in an OverflowError? in sqlite. Attaching a draft patch in a sec.

Python Traceback

Traceback (most recent call last):
  File "/home/tim/code/trac/trac-trunk/trac/web/main.py", line 417, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/tim/code/trac/trac-trunk/trac/web/main.py", line 197, in dispatch
    resp = chosen_handler.process_request(req)
  File "/home/tim/code/trac/trac-trunk/trac/ticket/web_ui.py", line 158, in process_request
    return self._process_ticket_request(req)
  File "/home/tim/code/trac/trac-trunk/trac/ticket/web_ui.py", line 413, in _process_ticket_request
    ticket = Ticket(self.env, id, version=version)
  File "/home/tim/code/trac/trac-trunk/trac/ticket/model.py", line 45, in __init__
    self._fetch_ticket(tkt_id, db)
  File "/home/tim/code/trac/trac-trunk/trac/ticket/model.py", line 91, in _fetch_ticket
    % ','.join(std_fields), (tkt_id,))
  File "/home/tim/code/trac/trac-trunk/trac/db/util.py", line 50, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
  File "/home/tim/code/trac/trac-trunk/trac/db/sqlite_backend.py", line 58, in execute
    args or [])
  File "/home/tim/code/trac/trac-trunk/trac/db/sqlite_backend.py", line 50, in _rollback_on_error
    return function(self, *args, **kwargs)
OverflowError: long too big to convert

Attachments

prevent-overflow.diff (0.9 KB) - added by thatch 8 months ago.

Change History

Changed 8 months ago by thatch

Changed 8 months ago by cboos

I'd rather re-use the check done in r4808, as that would enforce the same rules everywhere, something like:

class Ticket(object):
    def __init__(self, tkt_id):
       ...
       row = None
       if Ticket.id_is_valid(tkt_id):
          ...

    id_is_valid = staticmethod(lambda num: 0 < num <= 2 << 30)

and also reuse Ticket.id_is_valid() in the r4808 context, of course.

Changed 8 months ago by thatch

  • owner changed from cboos to thatch
  • status changed from new to assigned

Okay. I was torn between the two alternatives, since your way limits ticket ids, period. Mine only limits them on sqlite. I suppose we can just officially say that Trac requires code changes to handle more than approximately one billion bugs then, and be consistent about it?

Changed 8 months ago by cboos

:-)

Yet another alternative approach would be to have a Ticket.normalize_id method, which would allow us to handle str input as well:

    def normalize_id(num):
        try:
            num = int(num)
            if 0 < num <= 2 << 30:
                return num
        except ValueError:
            pass

... as you seem fit.

Changed 7 months ago by cboos

  • status changed from assigned to closed
  • resolution set to fixed

Implemented something like comment:1 in r6832.

Add/Change #7056 (Large ticket numbers can trigger overflow error rather than "Ticket does not exist" on sqlite)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from thatch. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.