bzr: ERROR: exceptions.SystemError: Negative size passed to PyString_FromStringAndSize when dirstate file has additional \0 at the end of the file

Bug #226036 reported by cbr
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Confirmed
Undecided
Unassigned

Bug Description

if a dirstate file ends up with a spare \0 at the end of the file, the parser croaks. This may be happening because of the use of truncate()

I am running bzr via sftp over openvpn from a laptop to a server.
bzr return a seg-fault when I try to commit
See the following

flyvemaskine:~/src/work/dversion> bzr commit
Segmentation fault
flyvemaskine:~/src/work/dversion> bzr status
Segmentation fault

flyvemaskine:~/src/work/dversion> bzr check
checked branch file:///home/cbr/src/work/dversion/ format Bazaar Branch Format 6 (bzr 0.15)
checked repository <bzrlib.transport.local.LocalTransport url=file:///home/cbr/src/work/> format <RepositoryFormatKnitPack1>
bzr: ERROR: exceptions.SystemError: Negative size passed to PyString_FromStringAndSize

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 834, in ...
  File "_dirstate_helpers_c.pyx", line 661, in _dirstate_helpers_c.Reader._parse_dirblocks
  File "_dirstate_helpers_c.pyx", line 626, in _dirstate_helpers_c.Reader._get_entry
SystemError: Negative size passed to PyString_FromStringAndSize

bzr 1.3.1 on python 2.5.2.final.0 (linux2)
arguments: ['/usr/bin/bzr', 'check']

Revision history for this message
edymtt (edymtt) wrote :
Download full text (5.6 KiB)

I think I'm having the same problem. I have the following setup:

 * I use bzr 1.5 under Ubuntu 8.04;
 * Ubuntu is running under VirtualBox 1.6 with Windows XP Professional SP2 as host OS;
 * the branch is on a NTFS partition and is accessed by Ubuntu through a (permanent) shared folder made with VirtualBox.

I can use the branch without problems for a while, then suddenly bzr throws an exception. If I delete the .bzr directory and recreate the branch the branch works fine... until the next "corruption". Below the output - first I invoke status, next a check:

ermiotto@hardy-vbox:/mnt/shared/intelligenti/progetto_si$ bzr status
bzr: ERROR: exceptions.SystemError: Negative size passed to PyString_FromStringAndSize

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 846, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 797, in run_bzr
    ret = run(*run_argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 499, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 807, in ignore_pipe
    result = func(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/bzrlib/builtins.py", line 178, in run
    show_pending=not no_pending)
  File "/usr/lib/python2.5/site-packages/bzrlib/status.py", line 117, in show_tree_status
    want_unversioned=want_unversioned)
  File "/usr/lib/python2.5/site-packages/bzrlib/tree.py", line 93, in changes_from
    want_unversioned=want_unversioned,
  File "/usr/lib/python2.5/site-packages/bzrlib/decorators.py", line 127, in read_locked
    return unbound(self, *args, **kwargs)
  File "/usr/lib/python2.5/site-packages/bzrlib/tree.py", line 734, in compare
    want_unversioned=want_unversioned)
  File "/usr/lib/python2.5/site-packages/bzrlib/delta.py", line 217, in _compare_trees
    want_unversioned=want_unversioned):
  File "/usr/lib/python2.5/site-packages/bzrlib/workingtree_4.py", line 1836, in iter_changes
    state._read_dirblocks_if_needed()
  File "/usr/lib/python2.5/site-packages/bzrlib/dirstate.py", line 1963, in _read_dirblocks_if_needed
    _read_dirblocks(self)
  File "_dirstate_helpers_c.pyx", line 694, in _dirstate_helpers_c._read_dirblocks_c
  File "_dirstate_helpers_c.pyx", line 661, in _dirstate_helpers_c.Reader._parse_dirblocks
  File "_dirstate_helpers_c.pyx", line 583, in _dirstate_helpers_c.Reader._get_entry
  File "_dirstate_helpers_c.pyx", line 502, in _dirstate_helpers_c.Reader.get_next_str
SystemError: Negative size passed to PyString_FromStringAndSize

bzr 1.5 on python 2.5.2 (linux2)
arguments: ['/usr/bin/bzr', 'status']
encoding: 'UTF-8', fsenc: 'UTF-8', lang: 'en_US.UTF-8'
plugins:
  bzrtools /usr/lib/python2.5/site-packages/bzrlib/plugins/bzrtools [1.5.0]
  launchpad /usr/lib/python2.5/site-packages/bzrlib/plugins/launchpad [unknown]
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.
ermiotto@hardy-vbox:/mn...

Read more...

Revision history for this message
James Westby (james-w) wrote :

Hi,

Would someone be able to provide a copy of the .bzr/checkout/dirstate
from a branch that exhibits this behaviour?

Thanks,

James

Changed in bzr:
status: New → Incomplete
Revision history for this message
edymtt (edymtt) wrote :

Hi,

I've attached the .bzr/checkout/dirstate from a corrupted branch.

  Eric

Revision history for this message
James Westby (james-w) wrote : Re: [Bug 226036] Re: bzr: ERROR: exceptions.SystemError: Negative size passed to PyString_FromStringAndSize

On Tue, 2008-06-17 at 17:31 +0000, edymtt wrote:
> Hi,
>
> I've attached the .bzr/checkout/dirstate from a corrupted branch.

Thanks.

The code in question is

    cdef char *get_next(self, int *size):
        """Return a pointer to the start of the next field."""
        cdef char *next
        next = self.cur_cstr
        self.cur_cstr = <char*>memchr(next, c'\0', self.end_cstr-next)
        size[0] = self.cur_cstr - next
        self.cur_cstr = self.cur_cstr + 1
        return next

    cdef object get_next_str(self):
        """Get the next field as a Python string."""
        cdef int size
        cdef char *next
        next = self.get_next(&size)
        return PyString_FromStringAndSize(next, size)

with the last line causing the error.

If memchr fails to find the null then it will return NULL, and you
will end up with a negative number.

You file seems to have an extra null byte at the end, which may well
be cause of the problem.

Thanks,

James

Revision history for this message
edymtt (edymtt) wrote : Re: bzr: ERROR: exceptions.SystemError: Negative size passed to PyString_FromStringAndSize

Hi,

I've found the time to delete the extra null byte at the end of my .bzr/checkout/dirstate. bzr status gave me no error.

Since I had modified files in that branch, I did a commit. It went well, but next bzr status gave me the error we are discussing in this bug. I deleted the null byte again and I had no problem with bzr status and bzr check.

Thanks for the tip, James!

  Eric

summary: bzr: ERROR: exceptions.SystemError: Negative size passed to
- PyString_FromStringAndSize
+ PyString_FromStringAndSize when dirstate file has additional \0 at the
+ end of the file
description: updated
description: updated
Revision history for this message
Robert Collins (lifeless) wrote :

I would change 'space' to 'spare' but I'm getting the red border (bad json) error and after 10 edit attempts am moving on.

Vincent Ladeuil (vila)
description: updated
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for Bazaar because there has been no activity for 60 days.]

Changed in bzr:
status: Incomplete → Expired
Jelmer Vernooij (jelmer)
Changed in bzr:
status: Expired → Confirmed
Jelmer Vernooij (jelmer)
tags: added: check-for-breezy
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.