LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package zip | 5 package zip |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "compress/flate" | 9 "compress/flate" |
10 "encoding/binary" | 10 "encoding/binary" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 d := make([]byte, filenameLen+extraLen+commentLen) | 231 d := make([]byte, filenameLen+extraLen+commentLen) |
232 if _, err := io.ReadFull(r, d); err != nil { | 232 if _, err := io.ReadFull(r, d); err != nil { |
233 return err | 233 return err |
234 } | 234 } |
235 f.Name = string(d[:filenameLen]) | 235 f.Name = string(d[:filenameLen]) |
236 f.Extra = d[filenameLen : filenameLen+extraLen] | 236 f.Extra = d[filenameLen : filenameLen+extraLen] |
237 f.Comment = string(d[filenameLen+extraLen:]) | 237 f.Comment = string(d[filenameLen+extraLen:]) |
238 | 238 |
239 if len(f.Extra) > 0 { | 239 if len(f.Extra) > 0 { |
240 b := readBuf(f.Extra) | 240 b := readBuf(f.Extra) |
241 » » for len(b) > 3 { // need at least tag and size | 241 » » for len(b) >= 4 { // need at least tag and size |
242 tag := b.uint16() | 242 tag := b.uint16() |
243 size := b.uint16() | 243 size := b.uint16() |
244 if int(size) > len(b) { | 244 if int(size) > len(b) { |
245 return ErrFormat | 245 return ErrFormat |
246 } | 246 } |
247 if tag == zip64ExtraId { | 247 if tag == zip64ExtraId { |
248 // update directory values from the zip64 extra
block | 248 // update directory values from the zip64 extra
block |
249 eb := readBuf(b) | 249 eb := readBuf(b) |
250 if len(eb) >= 8 { | 250 if len(eb) >= 8 { |
251 f.UncompressedSize64 = eb.uint64() | 251 f.UncompressedSize64 = eb.uint64() |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 v := binary.LittleEndian.Uint32(*b) | 427 v := binary.LittleEndian.Uint32(*b) |
428 *b = (*b)[4:] | 428 *b = (*b)[4:] |
429 return v | 429 return v |
430 } | 430 } |
431 | 431 |
432 func (b *readBuf) uint64() uint64 { | 432 func (b *readBuf) uint64() uint64 { |
433 v := binary.LittleEndian.Uint64(*b) | 433 v := binary.LittleEndian.Uint64(*b) |
434 *b = (*b)[8:] | 434 *b = (*b)[8:] |
435 return v | 435 return v |
436 } | 436 } |
LEFT | RIGHT |