Ticket #1669: 1.9.1-debugging-ticket1669.diff.txt

File 1.9.1-debugging-ticket1669.diff.txt, 6.8 KB (added by zooko, at 2012-06-19T03:49:07Z)
Line 
1diff -u -r '--exclude=.git' 1.9.1/src/allmydata/mutable/common.py 1.9.1-debugging-ticket1669/src/allmydata/mutable/common.py
2--- 1.9.1/src/allmydata/mutable/common.py       2012-01-12 12:05:20.000000000 -0400
3+++ 1.9.1-debugging-ticket1669/src/allmydata/mutable/common.py  2012-06-18 14:07:48.199757241 -0300
4@@ -1,5 +1,5 @@
5 
6-from allmydata.util import idlib
7+from allmydata.util import hashutil, idlib
8 from allmydata.util.spans import DataSpans
9 
10 MODE_CHECK = "MODE_CHECK" # query all peers
11@@ -53,6 +53,30 @@
12                                                                self.shnum,
13                                                                self.reason)
14 
15+def check_is_verinfo(x):
16+    if not isinstance(x, tuple):
17+        raise TypeError("This isn't a verinfo because its type is %s instead of tuple. %r" % (type(x), x,))
18+    if len(x) != 9:
19+        raise TypeError("This isn't a verinfo because its length is %s instead of 9. %r :: %s" % (len(x), x, type(x),))
20+    if not isinstance(x[0], (int, long)):
21+        raise TypeError("This isn't a verinfo because the type of its 0 element is %s instead of int/long. %r :: %s" % (type(x[0]), x, type(x),))
22+    if not hashutil.is_hash(x[1]):
23+        raise TypeError("This isn't a verinfo because its 1 element (%r :: %s) is not a hash. %r :: %s" % (x[1], type(x[1]), x, type(x),))
24+    if not hashutil.is_hash(x[2]):
25+        raise TypeError("This isn't a verinfo because its 2 element (%r :: %s) is not a hash. %r :: %s" % (x[2], type(x[2]), x, type(x),))
26+    if not isinstance(x[3], (int, long)):
27+        raise TypeError("This isn't a verinfo because the type of its 3 element is %s instead of int/long. %r :: %s" % (type(x[3]), x, type(x),))
28+    if not isinstance(x[4], (int, long)):
29+        raise TypeError("This isn't a verinfo because the type of its 4 element is %s instead of int/long. %r :: %s" % (type(x[4]), x, type(x),))
30+    if not isinstance(x[5], (int, long)):
31+        raise TypeError("This isn't a verinfo because the type of its 5 element is %s instead of int/long. %r :: %s" % (type(x[5]), x, type(x),))
32+    if not isinstance(x[6], (int, long)):
33+        raise TypeError("This isn't a verinfo because the type of its 6 element is %s instead of int/long. %r :: %s" % (type(x[6]), x, type(x),))
34+    if not isinstance(x[7], str):
35+        raise TypeError("This isn't a verinfo because the type of its 7 element is %s instead of str. %r :: %s" % (type(x[7]), x, type(x),))
36+    if not isinstance(x[8], tuple):
37+        raise TypeError("This isn't a verinfo because the type of its 8 element is %s instead of tuple. %r :: %s" % (type(x[7]), x, type(x),))
38+   
39 class UnknownVersionError(Exception):
40     """The share we received was of a version we don't recognize."""
41 
42diff -u -r '--exclude=.git' 1.9.1/src/allmydata/mutable/publish.py 1.9.1-debugging-ticket1669/src/allmydata/mutable/publish.py
43--- 1.9.1/src/allmydata/mutable/publish.py      2012-01-12 12:05:20.000000000 -0400
44+++ 1.9.1-debugging-ticket1669/src/allmydata/mutable/publish.py 2012-06-18 14:13:10.108501792 -0300
45@@ -16,7 +16,7 @@
46 from foolscap.api import eventually, fireEventually
47 
48 from allmydata.mutable.common import MODE_WRITE, MODE_CHECK, \
49-     UncoordinatedWriteError, NotEnoughServersError
50+     UncoordinatedWriteError, NotEnoughServersError, check_is_verinfo
51 from allmydata.mutable.servermap import ServerMap
52 from allmydata.mutable.layout import get_version_from_checkstring,\
53                                      unpack_mdmf_checkstring, \
54@@ -883,6 +883,7 @@
55 
56     def _record_verinfo(self):
57         self.versioninfo = self.writers.values()[0].get_verinfo()
58+        check_is_verinfo(self.versioninfo)
59 
60 
61     def _connection_problem(self, f, writer):
62diff -u -r '--exclude=.git' 1.9.1/src/allmydata/mutable/servermap.py 1.9.1-debugging-ticket1669/src/allmydata/mutable/servermap.py
63--- 1.9.1/src/allmydata/mutable/servermap.py    2012-01-12 12:05:20.000000000 -0400
64+++ 1.9.1-debugging-ticket1669/src/allmydata/mutable/servermap.py       2012-06-18 17:14:45.901013590 -0300
65@@ -13,7 +13,7 @@
66 from pycryptopp.publickey import rsa
67 
68 from allmydata.mutable.common import MODE_CHECK, MODE_ANYTHING, MODE_WRITE, MODE_READ, \
69-     CorruptShareError
70+     CorruptShareError, check_is_verinfo
71 from allmydata.mutable.layout import SIGNED_PREFIX_LENGTH, MDMFSlotReadProxy
72 
73 class UpdateStatus:
74@@ -631,6 +631,7 @@
75         to occur when the file is downloaded, or when the file is
76         updated.
77         """
78+        check_is_verinfo(verinfo)
79         if verinfo:
80             self._node._add_to_cache(verinfo, shnum, 0, data)
81 
82@@ -695,6 +696,7 @@
83             #   bytes of the share on the storage server, so we
84             #   shouldn't need to fetch anything at this step.
85             d2 = reader.get_verinfo()
86+            check_is_verinfo(d2)
87             d2.addErrback(lambda error, shnum=shnum, peerid=peerid, data=data:
88                 self._got_corrupt_share(error, shnum, peerid, data, lp))
89             # - Next, we need the signature. For an SDMF share, it is
90@@ -730,6 +732,8 @@
91                 # make the two routines share the value without
92                 # introducing more roundtrips?
93                 ds.append(reader.get_verinfo())
94+                v = ds[-1]
95+                check_is_verinfo(v)
96                 ds.append(reader.get_blockhashes())
97                 ds.append(reader.get_block_and_salt(self.start_segment))
98                 ds.append(reader.get_block_and_salt(self.end_segment))
99@@ -809,6 +813,7 @@
100             return None
101 
102         _, verinfo, signature, __, ___ = results
103+        check_is_verinfo(verinfo)
104         (seqnum,
105          root_hash,
106          saltish,
107@@ -831,6 +836,7 @@
108                    n,
109                    prefix,
110                    offsets_tuple)
111+        check_is_verinfo(verinfo)
112         # This tuple uniquely identifies a share on the grid; we use it
113         # to keep track of the ones that we've already seen.
114 
115@@ -880,6 +886,7 @@
116         """
117         assert len(results) == 4
118         verinfo, blockhashes, start, end = results
119+        check_is_verinfo(verinfo)
120         (seqnum,
121          root_hash,
122          saltish,
123@@ -902,6 +909,7 @@
124                    n,
125                    prefix,
126                    offsets_tuple)
127+        check_is_verinfo(verinfo)
128 
129         update_data = (blockhashes, start, end)
130         self._servermap.set_update_data_for_share_and_verinfo(share,
131diff -u -r '--exclude=.git' 1.9.1/src/allmydata/util/hashutil.py 1.9.1-debugging-ticket1669/src/allmydata/util/hashutil.py
132--- 1.9.1/src/allmydata/util/hashutil.py        2012-01-12 12:05:20.000000000 -0400
133+++ 1.9.1-debugging-ticket1669/src/allmydata/util/hashutil.py   2012-06-18 14:00:16.454852387 -0300
134@@ -209,3 +209,7 @@
135 BACKUPDB_DIRHASH_TAG = "allmydata_backupdb_dirhash_v1"
136 def backupdb_dirhash(contents):
137     return tagged_hash(BACKUPDB_DIRHASH_TAG, contents)
138+
139+def is_hash(x):
140+    return isinstance(x, str) and len(x) == CRYPTO_VAL_SIZE
141+