[Zodb-checkins] CVS: ZODB3/BTrees - BTreeItemsTemplate.c:1.18
Tim Peters
tim.one@comcast.net
Fri, 31 Jan 2003 15:13:35 -0500
Update of /cvs-repository/ZODB3/BTrees
In directory cvs.zope.org:/tmp/cvs-serv17086/BTrees
Modified Files:
BTreeItemsTemplate.c
Log Message:
BTreeItems_seek(): Even if i == pseudoindex on entry, bucket mutation
since the last call may have left us with an invalid index. Raise
RuntimeError instead of segfaulting (or picking up random trash) if so.
A new (and previously segfaulting) test case is courtesy of Steve
Alexander.
=== ZODB3/BTrees/BTreeItemsTemplate.c 1.17 => 1.18 ===
--- ZODB3/BTrees/BTreeItemsTemplate.c:1.17 Sat Jun 22 13:22:54 2002
+++ ZODB3/BTrees/BTreeItemsTemplate.c Fri Jan 31 15:13:02 2003
@@ -137,6 +137,7 @@
{
int delta, pseudoindex, currentoffset;
Bucket *b, *currentbucket;
+ int error;
pseudoindex = self->pseudoindex;
currentoffset = self->currentoffset;
@@ -210,6 +211,21 @@
}
assert(pseudoindex == i);
+
+ /* Alas, the user may have mutated the bucket since the last time we
+ * were called, and if they deleted stuff, we may be pointing into
+ * trash memory now.
+ */
+ PER_USE_OR_RETURN(currentbucket, -1);
+ error = currentoffset < 0 || currentoffset >= currentbucket->len;
+ PER_ALLOW_DEACTIVATION(currentbucket);
+ PER_ACCESSED(currentbucket);
+ if (error) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "the bucket being iterated changed size");
+ return -1;
+ }
+
Py_INCREF(currentbucket);
Py_DECREF(self->currentbucket);
self->currentbucket = currentbucket;