From: Brian Warner Date: Tue, 4 Nov 2008 22:29:19 +0000 (-0700) Subject: immutable: tolerate filenode.read() with a size= that's too big, rather than hanging X-Git-Url: https://git.rkrishnan.org/pf/content/en/frontends/flags?a=commitdiff_plain;h=6fa41e738b4036efaf128e2b6a9ff284d5c4b0d6;p=tahoe-lafs%2Ftahoe-lafs.git immutable: tolerate filenode.read() with a size= that's too big, rather than hanging --- diff --git a/src/allmydata/immutable/filenode.py b/src/allmydata/immutable/filenode.py index 33395ef9..fbc00d86 100644 --- a/src/allmydata/immutable/filenode.py +++ b/src/allmydata/immutable/filenode.py @@ -221,7 +221,7 @@ class FileNode(_ImmutableFileNodeBase): def read(self, consumer, offset=0, size=None): if size is None: size = self.get_size() - offset - + size = min(size, self.get_size() - offset) if offset == 0 and size == self.get_size(): # don't use the cache, just do a normal streaming download diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 5a2fff15..618d4af7 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -202,6 +202,11 @@ class SystemTest(SystemTestMixin, unittest.TestCase): def _read_tail_done(mc): self.failUnlessEqual("".join(mc.chunks), DATA[2:]) d.addCallback(_read_tail_done) + d.addCallback(lambda ign: + n.read(MemoryConsumer(), size=len(DATA)+1000)) + def _read_too_much(mc): + self.failUnlessEqual("".join(mc.chunks), DATA) + d.addCallback(_read_too_much) return d d.addCallback(_test_read)