icat4json 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dd323bceeb209a0a0e02f93a300d1c02afbbdbad8869ef79e10f6d27c8697c7
4
- data.tar.gz: 74a68c32b863e826a68c381f5ea53bf344c1c92d0dd6218309ba373efd8e2fc5
3
+ metadata.gz: 3727e373ff93beff148bf4f2706160925524744a37942a00c9583b79c6467197
4
+ data.tar.gz: 990b772c6e358431e5ad314d36d2fdb40e8ae933b78d3378462975a40d7444d4
5
5
  SHA512:
6
- metadata.gz: ada5d5ed8c8ce2ed1ed8b0bd0d66cf1044dd0b9885173d20212a43cde1ee486cb64817b905addc6f5c9776496bb22f5e41fc6f88b297d13ee659a1f7c2fb694a
7
- data.tar.gz: d976dfe378aab5958b36d5bdb333b0bba0b8d84097527c0bf61fc73b2388d46698f09e59b94c62918ddf6a22c9f4cbe6f90b1666312f6c86dae2badcd7d3f59e
6
+ metadata.gz: 38b40e3e9c40f853c1781d9db001ff801b64b325f8d2e01606ecc5cf07964d36f79cd838308f178b4bd11eb8067f7ed61ffcb14158947c5b862b11a176ce2a6f
7
+ data.tar.gz: 6e23c34687d8f1602a8bd78c8fe84464168c8b9a568bae236414ec1a42382911e1fa94acf1f8607ccd5aa6cd54b8a6923ce3edc25e5fb3b210988c5373fd22b2
data/icat4json.gemspec CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.description = "A Ruby gem to fetch and parse vulnerability information from IPA's icat for JSON feed. Provides easy access to Japanese vulnerability database."
12
12
  spec.homepage = "https://github.com/masoo/icat4json"
13
13
  spec.license = "MIT"
14
+ spec.metadata["rubygems_mfa_required"] = "true"
14
15
  spec.files = Dir.glob("{lib}/**/*").push(
15
16
  "LICENSE.txt", "README.md", "icat4json.gemspec"
16
17
  ).select { |f| File.file?(f) }
@@ -1,3 +1,3 @@
1
1
  module ICat4JSON
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.2"
3
3
  end
data/lib/icat4json.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "icat4json/version"
2
2
  require "net/http"
3
+ require "openssl"
3
4
  require "uri"
4
5
  require "json"
5
6
 
@@ -31,16 +32,31 @@ module ICat4JSON
31
32
  http.open_timeout = 10
32
33
  http.read_timeout = 10
33
34
 
34
- response = http.request(Net::HTTP::Get.new(uri))
35
- unless response.is_a?(Net::HTTPSuccess)
36
- raise ConnectionError, "HTTP request failed with status #{response.code}"
35
+ body = +""
36
+ # 全体を読み込んでから比較すると(gzip 展開後の)巨大な応答がメモリに載るため、
37
+ # 受信しながらサイズを確認して上限超過の時点で打ち切る
38
+ http.request(Net::HTTP::Get.new(uri)) do |response|
39
+ unless response.is_a?(Net::HTTPSuccess)
40
+ raise ConnectionError, "HTTP request failed with status #{response.code}"
41
+ end
42
+
43
+ response.read_body do |chunk|
44
+ body << chunk
45
+ if body.bytesize > MAX_RESPONSE_SIZE
46
+ raise Error, "Response too large: exceeds #{MAX_RESPONSE_SIZE} bytes"
47
+ end
48
+ end
37
49
  end
50
+ to_utf8(body)
51
+ rescue SocketError, SystemCallError, IOError, OpenSSL::SSL::SSLError,
52
+ Timeout::Error, Net::ProtocolError, Net::HTTPBadResponse => e
53
+ raise ConnectionError, "HTTP request failed: #{e.class}: #{e.message}"
54
+ end
38
55
 
39
- body = response.body
40
- raise Error, "Response too large: #{body.bytesize} bytes" if body.bytesize > MAX_RESPONSE_SIZE
41
- body.encode("UTF-8")
42
- rescue SocketError, Timeout::Error => e
43
- raise ConnectionError, "HTTP request failed: #{e.message}"
56
+ def to_utf8(body)
57
+ body.force_encoding(Encoding::UTF_8)
58
+ raise ParseError, "Response is not valid UTF-8" unless body.valid_encoding?
59
+ body
44
60
  end
45
61
 
46
62
  def parse_json(raw)
@@ -50,6 +66,8 @@ module ICat4JSON
50
66
  end
51
67
 
52
68
  def build_icat_data(json)
69
+ raise ParseError, "Unexpected JSON structure: top level must be an object" unless json.is_a?(Hash)
70
+
53
71
  ICATData.new(
54
72
  itemdata: build_item_data(json["itemdata"]),
55
73
  docTitle: json["docTitle"],
@@ -61,7 +79,11 @@ module ICat4JSON
61
79
 
62
80
  def build_item_data(items)
63
81
  return [] if items.nil?
82
+ raise ParseError, "Unexpected JSON structure: itemdata must be an array" unless items.is_a?(Array)
83
+
64
84
  items.map do |h|
85
+ raise ParseError, "Unexpected JSON structure: itemdata elements must be objects" unless h.is_a?(Hash)
86
+
65
87
  ItemData.new(
66
88
  item_title: h["item_title"],
67
89
  item_link: h["item_link"],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icat4json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUNABARA Masao
@@ -95,7 +95,8 @@ files:
95
95
  homepage: https://github.com/masoo/icat4json
96
96
  licenses:
97
97
  - MIT
98
- metadata: {}
98
+ metadata:
99
+ rubygems_mfa_required: 'true'
99
100
  rdoc_options: []
100
101
  require_paths:
101
102
  - lib
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubygems_version: 4.0.16
114
+ rubygems_version: 4.0.20
114
115
  specification_version: 4
115
116
  summary: Ruby client for IPA's icat for JSON vulnerability feed
116
117
  test_files: []