rubyzip 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubyzip might be problematic. Click here for more details.

Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zip/file.rb +2 -1
  3. data/lib/zip/inflater.rb +15 -44
  4. data/lib/zip/ioextras/abstract_input_stream.rb +5 -1
  5. data/lib/zip/version.rb +1 -1
  6. data/test/alltests.rb +18 -0
  7. data/test/basic_zip_file_test.rb +64 -0
  8. data/test/central_directory_entry_test.rb +73 -0
  9. data/test/central_directory_test.rb +100 -0
  10. data/test/data/file1.txt +46 -0
  11. data/test/data/file1.txt.deflatedData +0 -0
  12. data/test/data/file2.txt +1504 -0
  13. data/test/data/file2.txt.other +0 -0
  14. data/test/data/globTest.zip +0 -0
  15. data/test/data/globTest/foo.txt +0 -0
  16. data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  17. data/test/data/globTest/food.txt +0 -0
  18. data/test/data/mimetype +1 -0
  19. data/test/data/notzippedruby.rb +7 -0
  20. data/test/data/rubycode.zip +0 -0
  21. data/test/data/rubycode2.zip +0 -0
  22. data/test/data/testDirectory.bin +0 -0
  23. data/test/data/zip64-sample.zip +0 -0
  24. data/test/data/zipWithDirs.zip +0 -0
  25. data/test/deflater_test.rb +62 -0
  26. data/test/dummy.txt +1 -0
  27. data/test/entry_set_test.rb +125 -0
  28. data/test/entry_test.rb +165 -0
  29. data/test/errors_test.rb +36 -0
  30. data/test/extra_field_test.rb +69 -0
  31. data/test/file_extract_directory_test.rb +55 -0
  32. data/test/file_extract_test.rb +90 -0
  33. data/test/file_split_test.rb +60 -0
  34. data/test/file_test.rb +568 -0
  35. data/test/filesystem/dir_iterator_test.rb +62 -0
  36. data/test/filesystem/directory_test.rb +131 -0
  37. data/test/filesystem/file_mutating_test.rb +100 -0
  38. data/test/filesystem/file_nonmutating_test.rb +505 -0
  39. data/test/filesystem/file_stat_test.rb +66 -0
  40. data/test/gentestfiles.rb +134 -0
  41. data/test/inflater_test.rb +14 -0
  42. data/test/input_stream_test.rb +170 -0
  43. data/test/ioextras/abstract_input_stream_test.rb +103 -0
  44. data/test/ioextras/abstract_output_stream_test.rb +106 -0
  45. data/test/ioextras/fake_io_test.rb +18 -0
  46. data/test/ioextrastest.rb +233 -0
  47. data/test/local_entry_test.rb +153 -0
  48. data/test/odt_test_fix.rb +30 -0
  49. data/test/output_stream_test.rb +114 -0
  50. data/test/pass_thru_compressor_test.rb +31 -0
  51. data/test/pass_thru_decompressor_test.rb +15 -0
  52. data/test/sample.odt +0 -0
  53. data/test/settings_test.rb +71 -0
  54. data/test/test_helper.rb +228 -0
  55. data/test/unicode_file_names_and_comments_test.rb +40 -0
  56. data/test/zip64_full_test.rb +49 -0
  57. data/test/zip64_support_test.rb +15 -0
  58. metadata +107 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d23ddcc769403826e54f22ac7351086bd4dda0ad
4
- data.tar.gz: 6e45bc494896b948785b181b843393092c0a6a87
3
+ metadata.gz: 8f37f5862f1890546a9ceb653b406beea7daec34
4
+ data.tar.gz: 124b547d2a2999a5fb6cd99597721d8dd45347aa
5
5
  SHA512:
6
- metadata.gz: b2227b5f2243bf5921259930ab98d82b794b3bd4bfd47d787fbd2c58b0e9fefa3524dc6072eec66cafe79c8ac81f47efb8608c257750d4cab8fca0311c907ffa
7
- data.tar.gz: 262be035076ac7b7840190718d5191e47dc15847dec3e1e28c8fa415b1f423919ca444cedc544b22b23af4e1f2cd0de2911cacdd4a9816fb79abb1449fea52d6
6
+ metadata.gz: a2daaac5e981f3aada2d3426bb51f81e60f61f5e8807efe9a339286923722f7ee0b5b4f5d42f366cfe90d486491f070402b5583d77141c544ea01893da6f40b3
7
+ data.tar.gz: 9d8efdb1540364455f36610c8d0d7c31f785458d5666176778ce6d1d1fb568902eb87369d6393fa9875177a164b8444a452bcfd7ae2811785be6c89475fa5c6e
@@ -70,7 +70,7 @@ module Zip
70
70
  @comment = ''
71
71
  @create = create
72
72
  case
73
- when !buffer && ::File.exist?(file_name)
73
+ when !buffer && ::File.size?(file_name)
74
74
  @create = nil
75
75
  @exist_file_perms = ::File.stat(file_name).mode
76
76
  ::File.open(name, 'rb') do |f|
@@ -97,6 +97,7 @@ module Zip
97
97
  return zf unless block_given?
98
98
  begin
99
99
  yield zf
100
+ zf
100
101
  ensure
101
102
  zf.close
102
103
  end
@@ -4,42 +4,26 @@ module Zip
4
4
  super
5
5
  @zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
6
6
  @output_buffer = ''
7
- @output_buffer_pos = 0
8
7
  @has_returned_empty_string = false
9
8
  end
10
9
 
11
10
  def sysread(number_of_bytes = nil, buf = '')
12
- buf ||= ''
13
- buf.clear
14
11
  readEverything = number_of_bytes.nil?
15
- if readEverything
16
- buf << @output_buffer[@output_buffer_pos...@output_buffer.bytesize]
17
-
18
- move_output_buffer_pos(buf.bytesize)
19
- else
20
- buf << @output_buffer[@output_buffer_pos, number_of_bytes]
21
-
22
- move_output_buffer_pos(buf.bytesize)
23
-
24
- if buf.bytesize == number_of_bytes
25
- return buf
26
- end
27
- end
28
- while readEverything || buf.bytesize + @output_buffer.bytesize < number_of_bytes
12
+ while readEverything || @output_buffer.bytesize < number_of_bytes
29
13
  break if internal_input_finished?
30
- @output_buffer << internal_produce_input
14
+ @output_buffer << internal_produce_input(buf)
31
15
  end
32
- return value_when_finished(number_of_bytes, buf) if @output_buffer.bytesize == 0 && input_finished?
33
- end_index = (number_of_bytes.nil? ? @output_buffer.bytesize : number_of_bytes) - buf.bytesize
34
- data = @output_buffer[0...end_index]
35
-
36
- move_output_buffer_pos(data.bytesize)
37
-
38
- buf << data
16
+ return value_when_finished if @output_buffer.bytesize == 0 && input_finished?
17
+ end_index = number_of_bytes.nil? ? @output_buffer.bytesize : number_of_bytes
18
+ @output_buffer.slice!(0...end_index)
39
19
  end
40
20
 
41
21
  def produce_input
42
- sysread()
22
+ if (@output_buffer.empty?)
23
+ internal_produce_input
24
+ else
25
+ @output_buffer.slice!(0...(@output_buffer.length))
26
+ end
43
27
  end
44
28
 
45
29
  # to be used with produce_input, not read (as read may still have more data cached)
@@ -53,16 +37,7 @@ module Zip
53
37
 
54
38
  private
55
39
 
56
- def move_output_buffer_pos(inc)
57
- @output_buffer_pos += inc
58
- if @output_buffer_pos == @output_buffer.bytesize
59
- @output_buffer.clear
60
- @output_buffer_pos = 0
61
- end
62
- end
63
-
64
- def internal_produce_input
65
- buf = ''
40
+ def internal_produce_input(buf = '')
66
41
  retried = 0
67
42
  begin
68
43
  @zlib_inflater.inflate(@input_stream.read(Decompressor::CHUNK_SIZE, buf))
@@ -77,14 +52,10 @@ module Zip
77
52
  @zlib_inflater.finished?
78
53
  end
79
54
 
80
- def value_when_finished(number_of_bytes, buf) # mimic behaviour of ruby File object.
81
- if number_of_bytes.nil?
82
- buf
83
- elsif buf.bytesize == 0
84
- nil
85
- else
86
- buf
87
- end
55
+ def value_when_finished # mimic behaviour of ruby File object.
56
+ return if @has_returned_empty_string
57
+ @has_returned_empty_string = true
58
+ ''
88
59
  end
89
60
  end
90
61
  end
@@ -86,6 +86,10 @@ module Zip
86
86
  return @output_buffer.slice!(0...sep_index)
87
87
  end
88
88
 
89
+ def ungetc(byte)
90
+ @output_buffer = byte.chr + @output_buffer
91
+ end
92
+
89
93
  def flush
90
94
  ret_val = @output_buffer
91
95
  @output_buffer = ''
@@ -108,4 +112,4 @@ module Zip
108
112
  alias_method :each, :each_line
109
113
  end
110
114
  end
111
- end
115
+ end
@@ -1,3 +1,3 @@
1
1
  module Zip
2
- VERSION = '1.1.4'
2
+ VERSION = '1.1.5'
3
3
  end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/test'
11
+ end
12
+ Dir.chdir File.join(File.dirname(__FILE__))
13
+
14
+ $VERBOSE = true
15
+
16
+ require 'ioextrastest'
17
+ require 'ziptest'
18
+ require 'zipfilesystemtest'
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+
3
+ class BasicZipFileTest < MiniTest::Unit::TestCase
4
+ include AssertEntry
5
+
6
+ def setup
7
+ @zip_file = ::Zip::File.new(TestZipFile::TEST_ZIP2.zip_name)
8
+ @testEntryNameIndex=0
9
+ end
10
+
11
+ def test_entries
12
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names.sort,
13
+ @zip_file.entries.entries.sort.map { |e| e.name })
14
+ end
15
+
16
+ def test_each
17
+ count = 0
18
+ visited = {}
19
+ @zip_file.each {
20
+ |entry|
21
+ assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
22
+ assert(!visited.include?(entry.name))
23
+ visited[entry.name] = nil
24
+ count = count.succ
25
+ }
26
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
27
+ end
28
+
29
+ def test_foreach
30
+ count = 0
31
+ visited = {}
32
+ ::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) {
33
+ |entry|
34
+ assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
35
+ assert(!visited.include?(entry.name))
36
+ visited[entry.name] = nil
37
+ count = count.succ
38
+ }
39
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
40
+ end
41
+
42
+ def test_get_input_stream
43
+ count = 0
44
+ visited = {}
45
+ @zip_file.each do |entry|
46
+ assert_entry(entry.name, @zip_file.get_input_stream(entry), entry.name)
47
+ assert(!visited.include?(entry.name))
48
+ visited[entry.name] = nil
49
+ count = count.succ
50
+ end
51
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
52
+ end
53
+
54
+ def test_get_input_streamBlock
55
+ fileAndEntryName = @zip_file.entries.first.name
56
+ @zip_file.get_input_stream(fileAndEntryName) {
57
+ |zis|
58
+ assert_entryContentsForStream(fileAndEntryName,
59
+ zis,
60
+ fileAndEntryName)
61
+ }
62
+ end
63
+
64
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class ZipCentralDirectoryEntryTest < MiniTest::Unit::TestCase
4
+
5
+ def test_read_from_stream
6
+ File.open("test/data/testDirectory.bin", "rb") {
7
+ |file|
8
+ entry = ::Zip::Entry.read_c_dir_entry(file)
9
+
10
+ assert_equal("longAscii.txt", entry.name)
11
+ assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
12
+ assert_equal(106490, entry.size)
13
+ assert_equal(3784, entry.compressed_size)
14
+ assert_equal(0xfcd1799c, entry.crc)
15
+ assert_equal("", entry.comment)
16
+
17
+ entry = ::Zip::Entry.read_c_dir_entry(file)
18
+ assert_equal("empty.txt", entry.name)
19
+ assert_equal(::Zip::Entry::STORED, entry.compression_method)
20
+ assert_equal(0, entry.size)
21
+ assert_equal(0, entry.compressed_size)
22
+ assert_equal(0x0, entry.crc)
23
+ assert_equal("", entry.comment)
24
+
25
+ entry = ::Zip::Entry.read_c_dir_entry(file)
26
+ assert_equal("short.txt", entry.name)
27
+ assert_equal(::Zip::Entry::STORED, entry.compression_method)
28
+ assert_equal(6, entry.size)
29
+ assert_equal(6, entry.compressed_size)
30
+ assert_equal(0xbb76fe69, entry.crc)
31
+ assert_equal("", entry.comment)
32
+
33
+ entry = ::Zip::Entry.read_c_dir_entry(file)
34
+ assert_equal("longBinary.bin", entry.name)
35
+ assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
36
+ assert_equal(1000024, entry.size)
37
+ assert_equal(70847, entry.compressed_size)
38
+ assert_equal(0x10da7d59, entry.crc)
39
+ assert_equal('', entry.comment)
40
+
41
+ entry = ::Zip::Entry.read_c_dir_entry(file)
42
+ assert_equal(nil, entry)
43
+ # Fields that are not check by this test:
44
+ # version made by 2 bytes
45
+ # version needed to extract 2 bytes
46
+ # general purpose bit flag 2 bytes
47
+ # last mod file time 2 bytes
48
+ # last mod file date 2 bytes
49
+ # compressed size 4 bytes
50
+ # uncompressed size 4 bytes
51
+ # disk number start 2 bytes
52
+ # internal file attributes 2 bytes
53
+ # external file attributes 4 bytes
54
+ # relative offset of local header 4 bytes
55
+
56
+ # file name (variable size)
57
+ # extra field (variable size)
58
+ # file comment (variable size)
59
+
60
+ }
61
+ end
62
+
63
+ def test_ReadEntryFromTruncatedZipFile
64
+ fragment=""
65
+ File.open("test/data/testDirectory.bin") { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
66
+ fragment.extend(IOizeString)
67
+ entry = ::Zip::Entry.new
68
+ entry.read_c_dir_entry(fragment)
69
+ fail "ZipError expected"
70
+ rescue ::Zip::Error
71
+ end
72
+
73
+ end
@@ -0,0 +1,100 @@
1
+ require 'test_helper'
2
+
3
+ class ZipCentralDirectoryTest < MiniTest::Unit::TestCase
4
+
5
+ def test_read_from_stream
6
+ ::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") {
7
+ |zipFile|
8
+ cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
9
+
10
+ assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
11
+ assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) {
12
+ |cdirEntry, testEntryName|
13
+ cdirEntry.name == testEntryName
14
+ })
15
+ assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
16
+ }
17
+ end
18
+
19
+ def test_readFromInvalidStream
20
+ File.open("test/data/file2.txt", "rb") {
21
+ |zipFile|
22
+ cdir = ::Zip::CentralDirectory.new
23
+ cdir.read_from_stream(zipFile)
24
+ }
25
+ fail "ZipError expected!"
26
+ rescue ::Zip::Error
27
+ end
28
+
29
+ def test_ReadFromTruncatedZipFile
30
+ fragment=""
31
+ File.open("test/data/testDirectory.bin", "rb") { |f| fragment = f.read }
32
+ fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
33
+ fragment.extend(IOizeString)
34
+ entry = ::Zip::CentralDirectory.new
35
+ entry.read_from_stream(fragment)
36
+ fail "ZipError expected"
37
+ rescue ::Zip::Error
38
+ end
39
+
40
+ def test_write_to_stream
41
+ entries = [::Zip::Entry.new("file.zip", "flimse", "myComment", "somethingExtra"),
42
+ ::Zip::Entry.new("file.zip", "secondEntryName"),
43
+ ::Zip::Entry.new("file.zip", "lastEntry.txt", "Has a comment too")]
44
+ cdir = ::Zip::CentralDirectory.new(entries, "my zip comment")
45
+ File.open("test/data/generated/cdirtest.bin", "wb") { |f| cdir.write_to_stream(f) }
46
+ cdirReadback = ::Zip::CentralDirectory.new
47
+ File.open("test/data/generated/cdirtest.bin", "rb") { |f| cdirReadback.read_from_stream(f) }
48
+
49
+ assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
50
+ end
51
+
52
+ def test_write64_to_stream
53
+ ::Zip.write_zip64_support = true
54
+ entries = [::Zip::Entry.new("file.zip", "file1-little", "comment1", "", 200, 101, ::Zip::Entry::STORED, 200),
55
+ ::Zip::Entry.new("file.zip", "file2-big", "comment2", "", 18000000000, 102, ::Zip::Entry::DEFLATED, 20000000000),
56
+ ::Zip::Entry.new("file.zip", "file3-alsobig", "comment3", "", 15000000000, 103, ::Zip::Entry::DEFLATED, 21000000000),
57
+ ::Zip::Entry.new("file.zip", "file4-little", "comment4", "", 100, 104, ::Zip::Entry::DEFLATED, 121)]
58
+ [0, 250, 18000000300, 33000000350].each_with_index do |offset, index|
59
+ entries[index].local_header_offset = offset
60
+ end
61
+ cdir = ::Zip::CentralDirectory.new(entries, "zip comment")
62
+ File.open("test/data/generated/cdir64test.bin", "wb") { |f| cdir.write_to_stream(f) }
63
+ cdirReadback = ::Zip::CentralDirectory.new
64
+ File.open("test/data/generated/cdir64test.bin", "rb") { |f| cdirReadback.read_from_stream(f) }
65
+
66
+ assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
67
+ assert_equal(::Zip::VERSION_NEEDED_TO_EXTRACT_ZIP64, cdirReadback.instance_variable_get(:@version_needed_for_extract))
68
+ end
69
+
70
+ def test_equality
71
+ cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
72
+ "somethingExtra"),
73
+ ::Zip::Entry.new("file.zip", "secondEntryName"),
74
+ ::Zip::Entry.new("file.zip", "lastEntry.txt")],
75
+ "my zip comment")
76
+ cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
77
+ "somethingExtra"),
78
+ ::Zip::Entry.new("file.zip", "secondEntryName"),
79
+ ::Zip::Entry.new("file.zip", "lastEntry.txt")],
80
+ "my zip comment")
81
+ cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
82
+ "somethingExtra"),
83
+ ::Zip::Entry.new("file.zip", "secondEntryName"),
84
+ ::Zip::Entry.new("file.zip", "lastEntry.txt")],
85
+ "comment?")
86
+ cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
87
+ "somethingExtra"),
88
+ ::Zip::Entry.new("file.zip", "lastEntry.txt")],
89
+ "comment?")
90
+ assert_equal(cdir1, cdir1)
91
+ assert_equal(cdir1, cdir2)
92
+
93
+ assert(cdir1 != cdir3)
94
+ assert(cdir2 != cdir3)
95
+ assert(cdir2 != cdir3)
96
+ assert(cdir3 != cdir4)
97
+
98
+ assert(cdir3 != "hello")
99
+ end
100
+ end
@@ -0,0 +1,46 @@
1
+
2
+ AUTOMAKE_OPTIONS = gnu
3
+
4
+ EXTRA_DIST = test.zip
5
+
6
+ CXXFLAGS= -g
7
+
8
+ noinst_LIBRARIES = libzipios.a
9
+
10
+ bin_PROGRAMS = test_zip test_izipfilt test_izipstream
11
+ # test_flist
12
+
13
+ libzipios_a_SOURCES = backbuffer.h fcol.cpp fcol.h \
14
+ fcol_common.h fcolexceptions.cpp fcolexceptions.h \
15
+ fileentry.cpp fileentry.h flist.cpp \
16
+ flist.h flistentry.cpp flistentry.h \
17
+ flistscanner.h ifiltstreambuf.cpp ifiltstreambuf.h \
18
+ inflatefilt.cpp inflatefilt.h izipfilt.cpp \
19
+ izipfilt.h izipstream.cpp izipstream.h \
20
+ zipfile.cpp zipfile.h ziphead.cpp \
21
+ ziphead.h flistscanner.ll
22
+
23
+ # test_flist_SOURCES = test_flist.cpp
24
+
25
+ test_izipfilt_SOURCES = test_izipfilt.cpp
26
+
27
+ test_izipstream_SOURCES = test_izipstream.cpp
28
+
29
+ test_zip_SOURCES = test_zip.cpp
30
+
31
+ # Notice that libzipios.a is not specified as -L. -lzipios
32
+ # If it was, automake would not include it as a dependency.
33
+
34
+ # test_flist_LDADD = libzipios.a
35
+
36
+ test_izipfilt_LDADD = libzipios.a -lz
37
+
38
+ test_zip_LDADD = libzipios.a -lz
39
+
40
+ test_izipstream_LDADD = libzipios.a -lz
41
+
42
+
43
+
44
+ flistscanner.cc : flistscanner.ll
45
+ $(LEX) -+ -PFListScanner -o$@ $^
46
+