From a4e475ab56406d76ed0b131206d9bc0f7d85e541 Mon Sep 17 00:00:00 2001 From: alexmullins Date: Thu, 29 Oct 2015 23:12:02 -0500 Subject: [PATCH] add test for failing corrupt input into flate --- README.txt | 2 +- reader.go | 1 + reader_test.go | 32 +++++++++++++++++++++++++++++++- testdata/macbeth-act1.zip | Bin 0 -> 10057 bytes 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 testdata/macbeth-act1.zip diff --git a/README.txt b/README.txt index aa95b5d..177985b 100644 --- a/README.txt +++ b/README.txt @@ -11,7 +11,7 @@ hello.txt -> compress -> encrypt -> .zip -> decrypt -> decompress -> hello.txt Roadmap ============================================================================== -Reading - Almost done (TODO: check for AE-2 and skip CRC). +Reading - Working on it. Some bugs to work out (TODO: check for AE-2 and skip CRC). Writing - Not started. Testing - Needs more. diff --git a/reader.go b/reader.go index ff7909b..2ce8cfd 100644 --- a/reader.go +++ b/reader.go @@ -244,6 +244,7 @@ func decryptStream(ciphertext, key, iv []byte) io.Reader { return nil } stream := cipher.NewCTR(block, iv) + // Not decrypting stream correctly if the number of bytes being read is >16 reader := cipher.StreamReader{S: stream, R: bytes.NewReader(ciphertext)} return reader } diff --git a/reader_test.go b/reader_test.go index 751e965..2cf784f 100644 --- a/reader_test.go +++ b/reader_test.go @@ -660,9 +660,39 @@ func TestHelloWorldAes(t *testing.T) { t.Errorf("Expected to open readcloser: %v", err) } defer rc.Close() - io.Copy(&b, rc) + if _, err := io.Copy(&b, rc); err != nil { + t.Errorf("Expected to copy bytes to buffer: %v", err) + } } if !bytes.Equal([]byte(expecting), b.Bytes()) { t.Errorf("Expected ending content to be %s instead of %s", expecting, b.Bytes()) } } + +func TestMacbethAct1(t *testing.T) { + file := "macbeth-act1.zip" + expecting := "Exeunt" + var b bytes.Buffer + r, err := OpenReader(filepath.Join("testdata", file)) + if err != nil { + t.Errorf("Expected %s to open: %v", file, err) + } + defer r.Close() + for _, f := range r.File { + if !f.IsEncrypted() { + t.Errorf("Expected %s to be encrypted.", f.Name) + } + f.SetPassword([]byte("golang")) + rc, err := f.Open() + if err != nil { + t.Errorf("Expected to open readcloser: %v", err) + } + defer rc.Close() + if _, err := io.Copy(&b, rc); err != nil { + t.Errorf("Expected to copy bytes to buffer: %v", err) + } + } + if !bytes.Contains(b.Bytes(), []byte(expecting)) { + t.Errorf("Expected to find %s in the buffer %v", expecting, b.Bytes()) + } +} diff --git a/testdata/macbeth-act1.zip b/testdata/macbeth-act1.zip new file mode 100644 index 0000000000000000000000000000000000000000..8ee2aa23983d173c28e4330c7282cc0fe542eb63 GIT binary patch literal 10057 zcmZ{qV{9gXyX@cE*0x*Q-P*Qon_JtqZES7Zwr$&b>-PT7$-T)Z7IN(2uAqN0dv;Y8P036`2p|O#vvjv@@u`?sRv%51$1{44kASen3 z4RBiBw-}`}M_!57?@KW%7(0_hl`Hx-xMlh`(*B(q8Fs%>kNQhP`>U&4V3Ikc!1Tw} z#Z$hz`Im8>MjryIBaZTN-KHJJ!wqbFi@D>T4*o2nG^Ya zEbI%CeKAbx<>v<3z7pzaKkv;Afx5=v^){Z^%up1RA#FMjM8Z6+rLV}vkuMZqp)|9W zbKuoY&k2sbx-7*j>go?9qYfXzgrnY~i=bguKpJ7kSgQ2RUaxkYDIU!z=sktD@J4a< z3%9IEN86$s`b?_T$*nB{zYj{D#Wx$U7jYR@0GXG?{gKXe}yxb+oyhT#3>;z0Xw z)JJ)|;p-V0;5Jh@x4T|FvWvaesDR{GNG^Z2tNU9I867QPbmM4r$E{_slEkS=KfE>{ zeh|2$1ih^=Qpgp;Z1p8Uw+fTy20y;4BgPTCLfdx!&zw*sg&S$JolW= zEbIb+@v)~?pn=VFpET~O1d5cmbw8vf9u78*f7IFWtM=mwzgARsU{dTxwR1S+>a`T{%}Mp_ zGO5FDA@R9ZR(ROUxcI`GEy`#D?w?{SI{tJ>&D1Y*C~o7nA~l+br0ttGkhvUi~`cD*qR z%h?Wd;1h9T#Y$Tok7-Ab9A5T!HCWVEk_ulg8{C6oH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