Repository navigation
Commit 12a8efe
Bound the buffered read to the range the server declared
PartialBuffer represents a declared byte range of a remote file, but on the
non-stream path it called buffer.read() with no argument, consuming whatever the
server chose to send before the declared size was consulted. How much got
buffered was decided by the server rather than by the range requested: a client
asking for 100 bytes buffered 20 MB when the server streamed that much, which
defeats the purpose of fetching ranges at all.
Read at most `size` bytes instead, in a loop that tolerates short reads. A
single read() call is not enough: a socket-backed response can return fewer
bytes than requested while more are still coming, so reading once would silently
truncate. The data is written straight into the result buffer so no intermediate
copy of the whole range is held. The existing tests all use BytesIO, which never
short-reads, so these cases need their own tests.
RemoteFetcher.fetch also turned the server's Content-Range straight into that
size without checking it. A header whose end precedes its start, such as
"bytes 100-50/1000", produced a negative size, and PartialBuffer.read(0) then
computed a negative length, which for a file object means read everything.
Malformed values such as "bytes abc-def/1000", "bytes */1000" or an empty header
raised a bare ValueError out of the library. Both are now RemoteZipError.
Adds tests that a server sending more than it declared does not enlarge the
buffer, that a server sending less does not hang or raise, that short reads are
handled without truncation, and that invalid or malformed Content-Range values
are rejected.1 parent 87220b5 commit 12a8efe
2 files changed
Lines changed: 88 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
33 | 53 | | |
34 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
35 | 57 | | |
36 | 58 | | |
37 | 59 | | |
| |||
223 | 245 | | |
224 | 246 | | |
225 | 247 | | |
226 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
227 | 256 | | |
228 | 257 | | |
229 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
68 | 98 | | |
69 | 99 | | |
70 | 100 | | |
| |||
206 | 236 | | |
207 | 237 | | |
208 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
209 | 266 | | |
210 | 267 | | |
211 | 268 | | |
| |||
0 commit comments