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

Unified Diff: src/pkg/archive/tar/writer.go

Issue 162062: code review 162062: Robustness fixes for tar/archive. (Closed)
Patch Set: code review 162062: Robustness fixes for tar/archive. Created 15 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/archive/tar/reader_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/archive/tar/writer.go
===================================================================
--- a/src/pkg/archive/tar/writer.go
+++ b/src/pkg/archive/tar/writer.go
@@ -15,8 +15,9 @@
)
var (
- ErrWriteTooLong = os.NewError("write too long");
- ErrFieldTooLong = os.NewError("header field too long");
+ ErrWriteTooLong = os.NewError("write too long");
+ ErrFieldTooLong = os.NewError("header field too long");
+ ErrWriteAfterClose = os.NewError("write after close");
)
// A Writer provides sequential writing of a tar archive in POSIX.1 format.
@@ -108,7 +109,11 @@
// WriteHeader writes hdr and prepares to accept the file's contents.
// WriteHeader calls Flush if it is not the first header.
+// Calling after a Close will return ErrWriteAfterClose.
func (tw *Writer) WriteHeader(hdr *Header) os.Error {
+ if tw.closed {
+ return ErrWriteAfterClose
+ }
if tw.err == nil {
tw.Flush()
}
@@ -164,6 +169,10 @@
// Write returns the error ErrWriteTooLong if more than
// hdr.Size bytes are written after WriteHeader.
func (tw *Writer) Write(b []byte) (n int, err os.Error) {
+ if tw.closed {
+ err = ErrWriteTooLong;
+ return;
+ }
overwrite := false;
if int64(len(b)) > tw.nb {
b = b[0:tw.nb];
@@ -172,12 +181,15 @@
n, err = tw.w.Write(b);
tw.nb -= int64(n);
if err == nil && overwrite {
- err = ErrWriteTooLong
+ err = ErrWriteTooLong;
+ return;
}
tw.err = err;
return;
}
+// Close closes the tar archive, flushing any unwritten
+// data to the underlying writer.
func (tw *Writer) Close() os.Error {
if tw.err != nil || tw.closed {
return tw.err
« no previous file with comments | « src/pkg/archive/tar/reader_test.go ('k') | no next file » | no next file with comments »

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