pngcheck 0.2.4-x64-mingw32 → 0.2.6-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +4 -4
- data/lib/pngcheck/pngcheck.dll +0 -0
- data/lib/pngcheck/recipe.rb +40 -30
- data/lib/pngcheck/version.rb +1 -1
- data/lib/pngcheck.rb +42 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19e858ebfc5626d9f92a5dc16d03efd040086fb7200ef0cac049f5c0fe5298aa
|
4
|
+
data.tar.gz: 50874a7abc47e535220000ad3cb82ac3ec878bb4e9b4a1dd8b8f902a8c0db258
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32bfcb50afaa30e85225546b3341e315e960e95d04281451b5ceb398b1e523ca39c0effe33563af446edc2e832a73e21a3e4a3fbadc9daaf1822100261651e3f
|
7
|
+
data.tar.gz: 474ba89fc38db44b27aceb2aca4fe12f8f4cd643a3eeb77e348e80d80698f2df574f4c99319fa5ae75321b17ed8baceeedcd5d15c93a0782c32809949807a138
|
data/README.adoc
CHANGED
@@ -53,7 +53,7 @@ $ gem install pngcheck
|
|
53
53
|
|
54
54
|
=== Usage
|
55
55
|
|
56
|
-
====
|
56
|
+
==== PngCheck status codes
|
57
57
|
|
58
58
|
[source,ruby]
|
59
59
|
----
|
@@ -84,7 +84,7 @@ valid = PngCheck.check_file("spec/examples/correct.png")
|
|
84
84
|
Where:
|
85
85
|
|
86
86
|
* `valid` is `true` if the file is correct
|
87
|
-
* otherwise an exception
|
87
|
+
* otherwise an exception is raised. Possible exception types are `PngCheck::EmptyPngError`, `PngCheck::CorruptPngError`
|
88
88
|
|
89
89
|
|
90
90
|
==== Memory buffer processing
|
@@ -110,8 +110,8 @@ valid = PngCheck.check_buffer(data)
|
|
110
110
|
|
111
111
|
Where:
|
112
112
|
|
113
|
-
* `valid` is `true` if the
|
114
|
-
* otherwise an exception
|
113
|
+
* `valid` is `true` if the buffer is correct image
|
114
|
+
* otherwise an exception is raised. Possible exception types are `PngCheck::EmptyPngError`, `PngCheck::CorruptPngError`
|
115
115
|
|
116
116
|
|
117
117
|
==== Pre-validation with libpng-ruby
|
data/lib/pngcheck/pngcheck.dll
CHANGED
Binary file
|
data/lib/pngcheck/recipe.rb
CHANGED
@@ -13,12 +13,16 @@ module PngCheck
|
|
13
13
|
ROOT = Pathname.new(File.expand_path("../..", __dir__))
|
14
14
|
COMMON_FLAGS = "-shared -fPIC -Wall -O -DUSE_ZLIB"
|
15
15
|
|
16
|
-
def
|
16
|
+
def files_to_load_all
|
17
17
|
@files << {
|
18
18
|
url: "http://www.libpng.org/pub/png/src/pngcheck-3.0.3.tar.gz",
|
19
19
|
sha256: "c36a4491634af751f7798ea421321642f9590faa032eccb0dd5fb4533609dee6", # rubocop:disable Layout/LineLength
|
20
20
|
}
|
21
|
-
|
21
|
+
end
|
22
|
+
|
23
|
+
def files_to_load_cross
|
24
|
+
if target_platform.eql?("aarch64-linux") &&
|
25
|
+
!host_platform.eql?("aarch64-linux")
|
22
26
|
@files << {
|
23
27
|
url: "http://ports.ubuntu.com/pool/main/z/zlib/zlib1g-dev_1.2.11.dfsg-2ubuntu1.3_arm64.deb", # rubocop:disable Layout/LineLength
|
24
28
|
sha256: "0ebadc1ff2a70f0958d4e8e21ffa97d9fa4da23555eaae87782e963044a26fcf", # rubocop:disable Layout/LineLength
|
@@ -28,17 +32,27 @@ module PngCheck
|
|
28
32
|
|
29
33
|
def initialize
|
30
34
|
super("pngcheck", "3.0.3")
|
31
|
-
|
35
|
+
files_to_load_all
|
36
|
+
files_to_load_cross
|
32
37
|
@target = ROOT.join(@target).to_s
|
33
38
|
@printed = {}
|
34
39
|
end
|
35
40
|
|
41
|
+
def lib_filename
|
42
|
+
@lib_filename ||=
|
43
|
+
if MiniPortile.windows?
|
44
|
+
"pngcheck.dll"
|
45
|
+
else
|
46
|
+
"pngcheck.so"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def lib_workpath
|
51
|
+
@lib_workpath ||= File.join(work_path, lib_filename)
|
52
|
+
end
|
53
|
+
|
36
54
|
def make_cmd
|
37
|
-
|
38
|
-
"gcc #{COMMON_FLAGS} -o pngcheck.dll wrapper.c -lz"
|
39
|
-
else
|
40
|
-
"#{cc} #{cflags} #{COMMON_FLAGS} -o pngcheck.so wrapper.c -lz"
|
41
|
-
end
|
55
|
+
"#{cc} #{cflags} #{COMMON_FLAGS} -o #{lib_filename} wrapper.c -lz"
|
42
56
|
end
|
43
57
|
|
44
58
|
def cook_if_not
|
@@ -56,29 +70,25 @@ module PngCheck
|
|
56
70
|
|
57
71
|
def configure
|
58
72
|
FileUtils.cp(ROOT.join("ext", "wrapper.c"), work_path, verbose: false)
|
59
|
-
if target_platform.eql?("aarch64-linux")
|
73
|
+
if target_platform.eql?("aarch64-linux") &&
|
74
|
+
!host_platform.eql?("aarch64-linux")
|
60
75
|
extract_file("#{work_path}/../data.tar.xz", work_path.to_s)
|
61
76
|
end
|
62
77
|
end
|
63
78
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
out, st = Open3.capture2("file #{l}")
|
72
|
-
out = out.strip
|
73
|
-
|
74
|
-
raise "Failed to query file #{l}: #{out}" unless st.exitstatus.zero?
|
79
|
+
def verify_lib
|
80
|
+
begin
|
81
|
+
out, = Open3.capture2("file #{lib_workpath}")
|
82
|
+
rescue StandardError
|
83
|
+
message("Failed to call file, skipped library verification ...\n")
|
84
|
+
return
|
85
|
+
end
|
75
86
|
|
76
|
-
|
77
|
-
|
78
|
-
else
|
79
|
-
raise "Invalid file format '#{out}', '#{@target_format}' expected"
|
80
|
-
end
|
87
|
+
unless out.include?(target_format)
|
88
|
+
raise "Invalid file format '#{out.strip}', '#{@target_format}' expected"
|
81
89
|
end
|
90
|
+
|
91
|
+
message("Verifying #{lib_workpath} ... OK\n")
|
82
92
|
end
|
83
93
|
|
84
94
|
def install
|
@@ -86,7 +96,7 @@ module PngCheck
|
|
86
96
|
.grep(%r{/(?:lib)?[a-zA-Z0-9\-]+\.(?:so|dylib|dll)$})
|
87
97
|
|
88
98
|
FileUtils.cp_r(libs, ROOT.join("lib", "pngcheck"), verbose: false)
|
89
|
-
|
99
|
+
verify_lib
|
90
100
|
end
|
91
101
|
|
92
102
|
def execute(action, command, command_opts = {})
|
@@ -174,11 +184,11 @@ module PngCheck
|
|
174
184
|
|
175
185
|
def cflags
|
176
186
|
@cflags ||=
|
177
|
-
if target_platform.eql?(
|
178
|
-
!
|
179
|
-
""
|
180
|
-
else
|
187
|
+
if target_platform.eql?("aarch64-linux") &&
|
188
|
+
!host_platform.eql?("aarch64-linux")
|
181
189
|
"-I./usr/include -L./usr/lib/#{target_platform}-gnu"
|
190
|
+
else
|
191
|
+
""
|
182
192
|
end
|
183
193
|
end
|
184
194
|
# rubocop:enable Metrics/CyclomaticComplexity
|
data/lib/pngcheck/version.rb
CHANGED
data/lib/pngcheck.rb
CHANGED
@@ -5,8 +5,16 @@ require "tempfile"
|
|
5
5
|
require_relative "pngcheck/version"
|
6
6
|
|
7
7
|
module PngCheck
|
8
|
+
EMPTY_IMAGE = "Image is empty"
|
9
|
+
|
8
10
|
class CorruptPngError < StandardError; end
|
9
11
|
|
12
|
+
class EmptyPngError < StandardError
|
13
|
+
def initialize(msg = EMPTY_IMAGE)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
STATUS_OK = 0
|
11
19
|
STATUS_WARNING = 1 # an error in some circumstances but not in all
|
12
20
|
STATUS_MINOR_ERROR = 3 # minor spec errors (e.g., out-of-range values)
|
@@ -37,25 +45,49 @@ module PngCheck
|
|
37
45
|
|
38
46
|
class << self
|
39
47
|
def analyze_file(path)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
status = pngcheck_file(path, captured_stream.path, extra_msg)
|
44
|
-
@@semaphore.unlock
|
45
|
-
# we assume that pngcheck_file returns either captured_stream
|
46
|
-
# or extra message but not both
|
47
|
-
[status, captured_stream.read + extra_msg.get_string(16)]
|
48
|
-
end
|
48
|
+
return [STATUS_CRITICAL_ERROR, EMPTY_IMAGE] if File.zero? path
|
49
|
+
|
50
|
+
do_analyze_file(path)
|
49
51
|
end
|
50
52
|
|
51
53
|
def check_file(path)
|
52
54
|
status, info = analyze_file(path)
|
55
|
+
raise EmptyPngError.new if info.eql? EMPTY_IMAGE
|
53
56
|
raise CorruptPngError.new info unless status == STATUS_OK
|
54
57
|
|
55
58
|
true
|
56
59
|
end
|
57
60
|
|
58
61
|
def analyze_buffer(data)
|
62
|
+
return [STATUS_CRITICAL_ERROR, EMPTY_IMAGE] if data.empty?
|
63
|
+
|
64
|
+
do_analyze_buffer(data)
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_buffer(data)
|
68
|
+
status, info = analyze_buffer(data)
|
69
|
+
raise EmptyPngError.new if info.eql? EMPTY_IMAGE
|
70
|
+
raise CorruptPngError.new info unless status == STATUS_OK
|
71
|
+
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def do_analyze_file(path)
|
78
|
+
Tempfile.open("captured-stream-") do |captured_stream|
|
79
|
+
extra_msg = FFI::Buffer.alloc_out(EXTRA_MESSAGE_SIZE, 1, false)
|
80
|
+
@@semaphore.lock
|
81
|
+
status = pngcheck_file(path, captured_stream.path, extra_msg)
|
82
|
+
@@semaphore.unlock
|
83
|
+
# we assume that pngcheck_file returns either captured_stream
|
84
|
+
# or extra message but not both
|
85
|
+
|
86
|
+
[status, captured_stream.read + extra_msg.get_string(0)]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def do_analyze_buffer(data)
|
59
91
|
Tempfile.open("captured-stream-") do |captured_stream|
|
60
92
|
extra_msg = FFI::Buffer.alloc_out(EXTRA_MESSAGE_SIZE, 1, false)
|
61
93
|
mem_buf = FFI::MemoryPointer.new(:char, data.bytesize)
|
@@ -64,15 +96,8 @@ module PngCheck
|
|
64
96
|
status = pngcheck_buffer(mem_buf, data.bytesize, captured_stream.path,
|
65
97
|
extra_msg)
|
66
98
|
@@semaphore.unlock
|
67
|
-
[status, captured_stream.read + extra_msg.get_string(
|
99
|
+
[status, captured_stream.read + extra_msg.get_string(0)]
|
68
100
|
end
|
69
101
|
end
|
70
|
-
|
71
|
-
def check_buffer(data)
|
72
|
-
status, info = analyze_buffer(data)
|
73
|
-
raise CorruptPngError.new info unless status == STATUS_OK
|
74
|
-
|
75
|
-
true
|
76
|
-
end
|
77
102
|
end
|
78
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pngcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: x64-mingw32
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|