[MERGE][bug #186014] Fix Dirstate Pyrex parser to trap trailing garbage

John Arbash Meinel john.meinel at canonical.com
Tue Aug 19 17:01:25 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

We had a bug in the pyrex dirstate parser if it got to the end of the file and
there was no trailing '\0' character.

This changes two things. One it makes it so the 'get_next()' function properly
traps when there is no trailing '\0'. Second it preemptively wraps a size
check around all PyString_FromStringAndSize calls.

This shouldn't effect performance much, because the C checks should be fast,
and it only drops into python object mode when there is an error.

It also adds an explicit test that we get an AssertionError when we have
trailing garbage. I don't really *like* AssertionError for this, but it is the
error we have had so far.

Best I can come up with is a new "DirstateCorrupted" error if we don't want to
raise AssertionError.

Note that this doesn't give any way to fix the problem, it just gives a bit
more debug detail when encountering it, without having to disable the compiled
parser.

John
=:->

PS> Interestingly enough, some platforms segfault when you pass an invalid
size to PyString_FromStringAndSize and some just try to allocate way too much
memory and fail with a MemoryError.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIqu5VJdeBCYSNAAMRAlp2AJwIR7qEhxROTlIxxaZ3L4i+0Lj03wCgqqzY
3ys+G4Xs2yoMCbu9OYOy2q4=
=HNoJ
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dirstate_segv_186014.patch
Type: text/x-diff
Size: 9190 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20080819/ae273a49/attachment-0001.bin 


More information about the bazaar mailing list