Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(715)

Delta Between Two Patch Sets: src/pkg/archive/zip/reader.go

Issue 6854058: code review 6854058: archive/zip: handle extra data headers with no body (Closed)
Left Patch Set: diff -r dbf92f38bae0 https://go.googlecode.com/hg/ Created 11 years, 4 months ago
Right Patch Set: diff -r dbf92f38bae0 https://go.googlecode.com/hg/ Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/archive/zip/zip_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b