png_conform 0.1.0

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.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +19 -0
  4. data/.rubocop_todo.yml +197 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/CONTRIBUTING.md +323 -0
  7. data/Gemfile +13 -0
  8. data/LICENSE +43 -0
  9. data/README.adoc +859 -0
  10. data/Rakefile +10 -0
  11. data/SECURITY.md +147 -0
  12. data/docs/ARCHITECTURE.adoc +681 -0
  13. data/docs/CHUNK_TYPES.adoc +450 -0
  14. data/docs/CLI_OPTIONS.adoc +913 -0
  15. data/docs/COMPATIBILITY.adoc +616 -0
  16. data/examples/README.adoc +398 -0
  17. data/examples/advanced_usage.rb +304 -0
  18. data/examples/basic_usage.rb +210 -0
  19. data/exe/png_conform +6 -0
  20. data/lib/png_conform/analyzers/comparison_analyzer.rb +230 -0
  21. data/lib/png_conform/analyzers/metrics_analyzer.rb +176 -0
  22. data/lib/png_conform/analyzers/optimization_analyzer.rb +190 -0
  23. data/lib/png_conform/analyzers/resolution_analyzer.rb +274 -0
  24. data/lib/png_conform/bindata/chunk_structure.rb +153 -0
  25. data/lib/png_conform/bindata/jng_file.rb +79 -0
  26. data/lib/png_conform/bindata/mng_file.rb +97 -0
  27. data/lib/png_conform/bindata/png_file.rb +162 -0
  28. data/lib/png_conform/cli.rb +116 -0
  29. data/lib/png_conform/commands/check_command.rb +323 -0
  30. data/lib/png_conform/commands/list_command.rb +67 -0
  31. data/lib/png_conform/models/chunk.rb +84 -0
  32. data/lib/png_conform/models/chunk_info.rb +71 -0
  33. data/lib/png_conform/models/compression_info.rb +49 -0
  34. data/lib/png_conform/models/decoded_chunk_data.rb +143 -0
  35. data/lib/png_conform/models/file_analysis.rb +181 -0
  36. data/lib/png_conform/models/file_info.rb +91 -0
  37. data/lib/png_conform/models/image_info.rb +52 -0
  38. data/lib/png_conform/models/validation_error.rb +89 -0
  39. data/lib/png_conform/models/validation_result.rb +137 -0
  40. data/lib/png_conform/readers/full_load_reader.rb +113 -0
  41. data/lib/png_conform/readers/streaming_reader.rb +180 -0
  42. data/lib/png_conform/reporters/base_reporter.rb +53 -0
  43. data/lib/png_conform/reporters/color_reporter.rb +65 -0
  44. data/lib/png_conform/reporters/json_reporter.rb +18 -0
  45. data/lib/png_conform/reporters/palette_reporter.rb +48 -0
  46. data/lib/png_conform/reporters/quiet_reporter.rb +18 -0
  47. data/lib/png_conform/reporters/reporter_factory.rb +108 -0
  48. data/lib/png_conform/reporters/summary_reporter.rb +65 -0
  49. data/lib/png_conform/reporters/text_reporter.rb +66 -0
  50. data/lib/png_conform/reporters/verbose_reporter.rb +87 -0
  51. data/lib/png_conform/reporters/very_verbose_reporter.rb +33 -0
  52. data/lib/png_conform/reporters/visual_elements.rb +66 -0
  53. data/lib/png_conform/reporters/yaml_reporter.rb +18 -0
  54. data/lib/png_conform/services/profile_manager.rb +242 -0
  55. data/lib/png_conform/services/validation_service.rb +457 -0
  56. data/lib/png_conform/services/zlib_validator.rb +270 -0
  57. data/lib/png_conform/validators/ancillary/bkgd_validator.rb +140 -0
  58. data/lib/png_conform/validators/ancillary/chrm_validator.rb +178 -0
  59. data/lib/png_conform/validators/ancillary/cicp_validator.rb +202 -0
  60. data/lib/png_conform/validators/ancillary/gama_validator.rb +105 -0
  61. data/lib/png_conform/validators/ancillary/hist_validator.rb +147 -0
  62. data/lib/png_conform/validators/ancillary/iccp_validator.rb +243 -0
  63. data/lib/png_conform/validators/ancillary/itxt_validator.rb +280 -0
  64. data/lib/png_conform/validators/ancillary/mdcv_validator.rb +201 -0
  65. data/lib/png_conform/validators/ancillary/offs_validator.rb +132 -0
  66. data/lib/png_conform/validators/ancillary/pcal_validator.rb +289 -0
  67. data/lib/png_conform/validators/ancillary/phys_validator.rb +107 -0
  68. data/lib/png_conform/validators/ancillary/sbit_validator.rb +176 -0
  69. data/lib/png_conform/validators/ancillary/scal_validator.rb +180 -0
  70. data/lib/png_conform/validators/ancillary/splt_validator.rb +223 -0
  71. data/lib/png_conform/validators/ancillary/srgb_validator.rb +117 -0
  72. data/lib/png_conform/validators/ancillary/ster_validator.rb +111 -0
  73. data/lib/png_conform/validators/ancillary/text_validator.rb +129 -0
  74. data/lib/png_conform/validators/ancillary/time_validator.rb +132 -0
  75. data/lib/png_conform/validators/ancillary/trns_validator.rb +154 -0
  76. data/lib/png_conform/validators/ancillary/ztxt_validator.rb +173 -0
  77. data/lib/png_conform/validators/apng/actl_validator.rb +81 -0
  78. data/lib/png_conform/validators/apng/fctl_validator.rb +155 -0
  79. data/lib/png_conform/validators/apng/fdat_validator.rb +117 -0
  80. data/lib/png_conform/validators/base_validator.rb +241 -0
  81. data/lib/png_conform/validators/chunk_registry.rb +219 -0
  82. data/lib/png_conform/validators/critical/idat_validator.rb +77 -0
  83. data/lib/png_conform/validators/critical/iend_validator.rb +68 -0
  84. data/lib/png_conform/validators/critical/ihdr_validator.rb +160 -0
  85. data/lib/png_conform/validators/critical/plte_validator.rb +120 -0
  86. data/lib/png_conform/validators/jng/jdat_validator.rb +66 -0
  87. data/lib/png_conform/validators/jng/jhdr_validator.rb +116 -0
  88. data/lib/png_conform/validators/jng/jsep_validator.rb +66 -0
  89. data/lib/png_conform/validators/mng/back_validator.rb +87 -0
  90. data/lib/png_conform/validators/mng/clip_validator.rb +65 -0
  91. data/lib/png_conform/validators/mng/clon_validator.rb +45 -0
  92. data/lib/png_conform/validators/mng/defi_validator.rb +104 -0
  93. data/lib/png_conform/validators/mng/dhdr_validator.rb +104 -0
  94. data/lib/png_conform/validators/mng/disc_validator.rb +44 -0
  95. data/lib/png_conform/validators/mng/endl_validator.rb +65 -0
  96. data/lib/png_conform/validators/mng/fram_validator.rb +91 -0
  97. data/lib/png_conform/validators/mng/loop_validator.rb +75 -0
  98. data/lib/png_conform/validators/mng/mend_validator.rb +31 -0
  99. data/lib/png_conform/validators/mng/mhdr_validator.rb +69 -0
  100. data/lib/png_conform/validators/mng/move_validator.rb +61 -0
  101. data/lib/png_conform/validators/mng/save_validator.rb +39 -0
  102. data/lib/png_conform/validators/mng/seek_validator.rb +42 -0
  103. data/lib/png_conform/validators/mng/show_validator.rb +52 -0
  104. data/lib/png_conform/validators/mng/term_validator.rb +84 -0
  105. data/lib/png_conform/version.rb +5 -0
  106. data/lib/png_conform.rb +101 -0
  107. data/png_conform.gemspec +43 -0
  108. metadata +201 -0
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
data/SECURITY.md ADDED
@@ -0,0 +1,147 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ We release patches for security vulnerabilities. Currently supported versions:
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 0.1.x | :white_check_mark: |
10
+ | < 0.1 | :x: |
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ The PngConform team takes security bugs seriously. We appreciate your efforts to responsibly disclose your findings.
15
+
16
+ ### How to Report
17
+
18
+ **Please do not report security vulnerabilities through public GitHub issues.**
19
+
20
+ Instead, please report them via email to:
21
+
22
+ - **Email**: open.source@ribose.com
23
+ - **Subject**: [SECURITY] PngConform - Brief description
24
+
25
+ ### What to Include
26
+
27
+ Please include the following information in your report:
28
+
29
+ 1. **Type of issue** (e.g. buffer overflow, code injection, etc.)
30
+ 2. **Full paths of source file(s)** related to the manifestation of the issue
31
+ 3. **Location of the affected source code** (tag/branch/commit or direct URL)
32
+ 4. **Step-by-step instructions** to reproduce the issue
33
+ 5. **Proof-of-concept or exploit code** (if possible)
34
+ 6. **Impact of the issue**, including how an attacker might exploit it
35
+
36
+ ### What to Expect
37
+
38
+ You should receive a response within 48 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
39
+
40
+ After the initial reply to your report, the security team will:
41
+
42
+ 1. **Confirm the problem** and determine the affected versions
43
+ 2. **Audit code** to find any similar problems
44
+ 3. **Prepare fixes** for all supported versions
45
+ 4. **Release patches** as soon as possible
46
+
47
+ ### Disclosure Policy
48
+
49
+ - Security issues are disclosed publicly after a fix is released
50
+ - We ask that you give us a reasonable time to address the issue before making it public
51
+ - We will credit you in the disclosure (unless you prefer to remain anonymous)
52
+
53
+ ## Security Best Practices
54
+
55
+ When using PngConform:
56
+
57
+ ### File Input Validation
58
+
59
+ ```ruby
60
+ # Always validate file existence and size before processing
61
+ if File.exist?(path) && File.size(path) < MAX_FILE_SIZE
62
+ service = PngConform::Services::ValidationService.new
63
+ result = service.validate_file(path)
64
+ else
65
+ # Handle invalid file
66
+ end
67
+ ```
68
+
69
+ ### Resource Limits
70
+
71
+ ```ruby
72
+ # For production use, consider setting resource limits
73
+ MAX_FILE_SIZE = 100 * 1024 * 1024 # 100 MB
74
+ MAX_PROCESSING_TIME = 30 # seconds
75
+
76
+ # Use streaming mode for large files
77
+ service = PngConform::Services::ValidationService.new
78
+ result = service.validate_file(path, streaming: true)
79
+ ```
80
+
81
+ ### User Input Sanitization
82
+
83
+ ```ruby
84
+ # When processing user-uploaded files
85
+ require 'securerandom'
86
+
87
+ def process_uploaded_file(uploaded_file)
88
+ # Use secure temporary directory
89
+ temp_dir = File.join(Dir.tmpdir, SecureRandom.hex)
90
+ Dir.mkdir(temp_dir, 0700)
91
+
92
+ temp_path = File.join(temp_dir, "temp.png")
93
+
94
+ begin
95
+ File.open(temp_path, 'wb') do |f|
96
+ f.write(uploaded_file.read)
97
+ end
98
+
99
+ # Validate the file
100
+ service = PngConform::Services::ValidationService.new
101
+ result = service.validate_file(temp_path)
102
+
103
+ # Process result...
104
+ ensure
105
+ # Clean up
106
+ FileUtils.rm_rf(temp_dir)
107
+ end
108
+ end
109
+ ```
110
+
111
+ ### Dependency Management
112
+
113
+ - Keep dependencies up to date: `bundle update`
114
+ - Regularly run `bundle audit` to check for known vulnerabilities
115
+ - Subscribe to security advisories for Ruby and gem dependencies
116
+
117
+ ## Known Security Considerations
118
+
119
+ ### File Parsing
120
+
121
+ PngConform uses BinData for binary parsing, which is a well-tested library. However:
122
+
123
+ - **Large files**: Set reasonable file size limits to prevent resource exhaustion
124
+ - **Malformed files**: The library handles malformed files gracefully, but very complex files may consume significant memory
125
+ - **Decompression bombs**: zlib decompression has limits, but extremely compressed files could still be problematic
126
+
127
+ ### Regular Expression DoS (ReDoS)
128
+
129
+ All regular expressions in the codebase have been reviewed for potential ReDoS vulnerabilities. If you find any patterns that could cause exponential backtracking, please report them.
130
+
131
+ ## Security Updates
132
+
133
+ Security updates will be released as soon as possible after a vulnerability is confirmed. Updates will be announced via:
134
+
135
+ - GitHub Security Advisories
136
+ - RubyGems security notifications
137
+ - CHANGELOG.md with security notes
138
+
139
+ ## Acknowledgments
140
+
141
+ We appreciate the security research community's efforts to improve the security of PngConform. Security researchers who responsibly disclose vulnerabilities will be credited in:
142
+
143
+ - Security advisory
144
+ - CHANGELOG.md
145
+ - This document (if desired)
146
+
147
+ Thank you for helping keep PngConform and its users safe!