rdiscount 2.2.7.3 → 2.2.7.4

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: 1caa0d04b22615c5a7d74768bd60aea41afff91406b0557831180b8b08a25842
4
- data.tar.gz: 3d02b3120eda58da3b54dc162004d6a3ab14b56bd657796026d59931d9cb4088
3
+ metadata.gz: 0a482c6d06757896511681393e99f986552e02fd6735e55cf0f665a6543a058e
4
+ data.tar.gz: adc56e6fd1359cdfdd955f2262ecc18376c0d6a822d0476a713fe3cccb468991
5
5
  SHA512:
6
- metadata.gz: 11053a0e075ba81143cd3cce86f5ccf55d2769600b987734da2c42db817b539fd9ed444c3219fe4c9bfd7998abda905a78cd27b5404a68dc9afec58218062cdc
7
- data.tar.gz: 224c5b32b0dceeedff8e435d8467f331a1e14e210268464e3ee2ca5af658c17a2bd102661dd1895e48f1fea429eb97ab00142df72c2fbdfcad87b951d4def3b3
6
+ metadata.gz: 8d244073c29884550875767cedbb065b760d1d690e51558f67429fe3516665e2ab5758298d3aaed68f5e1242c7a116afa00578cf7d89d067ab681eb3a08d1472
7
+ data.tar.gz: c2e1999790db93a98d6a5d65ea3f9a8ff1010e49fc678f5baba006f0af61f24123f05bfecc08649dbd13bdbe58198da855d9584bf0c42bd1b5b5217422c4a92e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # RDiscount Changelog
2
2
 
3
+ ## Version 2.2.7.4 <small>(April 1, 2026)</small>
4
+
5
+ * Fix crash if `to_html` called on a string longer than INT_MAX (2 GiB of text).
6
+
3
7
  ## Version 2.2.7.3 <small>(December 31, 2023)</small>
4
8
 
5
9
  * Add Ruby 3.2 and 3.3 to continuous integration
data/Rakefile CHANGED
@@ -138,7 +138,7 @@ task :gather => 'discount/markdown.h' do |t|
138
138
  ]
139
139
 
140
140
  # Ensure configure.sh was run
141
- if not File.exists? 'discount/mkdio.h'
141
+ if not File.exist? 'discount/mkdio.h'
142
142
  abort "discount/mkdio.h not found. Did you run ./configure.sh in the discount directory?"
143
143
  end
144
144
 
@@ -225,7 +225,11 @@ file 'rdiscount.gemspec' => FileList['Rakefile','lib/rdiscount.rb'] do |f|
225
225
  files = `git ls-files`.
226
226
  split("\n").
227
227
  sort.
228
- reject{ |file| file =~ /^\./ || file =~ /^test\/MarkdownTest/ }.
228
+ reject{|file|
229
+ file =~ /^\./ ||
230
+ file =~ /^test\/MarkdownTest/ ||
231
+ file =~ /^CLAUDE\.md|ext\.diff$/
232
+ }.
229
233
  map{ |file| " #{file}" }.
230
234
  join("\n")
231
235
  # piece file back together and write...
data/ext/rdiscount.c CHANGED
@@ -1,4 +1,5 @@
1
1
  #include <stdio.h>
2
+ #include <limits.h>
2
3
  #include <locale.h>
3
4
  #include "ruby.h"
4
5
  #include "mkdio.h"
@@ -43,6 +44,18 @@ static AccessorFlagPair ACCESSOR_2_FLAG[] = {
43
44
 
44
45
  static VALUE rb_cRDiscount;
45
46
 
47
+ static int
48
+ rb_rdiscount__text_len(VALUE text)
49
+ {
50
+ long text_len = RSTRING_LEN(text);
51
+
52
+ if (text_len > INT_MAX) {
53
+ rb_raise(rb_eArgError, "markdown input too large");
54
+ }
55
+
56
+ return (int)text_len;
57
+ }
58
+
46
59
  int rb_rdiscount__get_flags(VALUE ruby_obj)
47
60
  {
48
61
  AccessorFlagPair *entry;
@@ -78,8 +91,10 @@ rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
78
91
  int szres;
79
92
  VALUE encoding;
80
93
  VALUE text = rb_funcall(self, rb_intern("text"), 0);
81
- VALUE buf = rb_str_buf_new(1024);
82
94
  Check_Type(text, T_STRING);
95
+ int text_len = rb_rdiscount__text_len(text); // may rb_raise
96
+
97
+ VALUE buf = rb_str_buf_new(1024);
83
98
 
84
99
  int flags = rb_rdiscount__get_flags(self);
85
100
 
@@ -94,7 +109,7 @@ rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
94
109
  char *old_locale = strdup(setlocale(LC_CTYPE, NULL));
95
110
  setlocale(LC_CTYPE, "C"); /* ASCII (and passthru characters > 127) */
96
111
 
97
- MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags);
112
+ MMIOT *doc = mkd_string(RSTRING_PTR(text), text_len, flags);
98
113
 
99
114
  if ( mkd_compile(doc, flags) ) {
100
115
  szres = mkd_document(doc, &res);
@@ -129,11 +144,12 @@ rb_rdiscount_toc_content(int argc, VALUE *argv, VALUE self)
129
144
  /* grab char pointer to markdown input text */
130
145
  VALUE text = rb_funcall(self, rb_intern("text"), 0);
131
146
  Check_Type(text, T_STRING);
147
+ int text_len = rb_rdiscount__text_len(text); // may rb_raise
132
148
 
133
149
  /* allocate a ruby string buffer and wrap it in a stream */
134
150
  VALUE buf = rb_str_buf_new(4096);
135
151
 
136
- MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags);
152
+ MMIOT *doc = mkd_string(RSTRING_PTR(text), text_len, flags);
137
153
 
138
154
  if ( mkd_compile(doc, flags) ) {
139
155
  szres = mkd_toc(doc, &res);
data/lib/rdiscount.rb CHANGED
@@ -24,7 +24,7 @@
24
24
  # end
25
25
  #
26
26
  class RDiscount
27
- VERSION = '2.2.7.3'
27
+ VERSION = '2.2.7.4'
28
28
 
29
29
  # Original Markdown formatted text.
30
30
  attr_reader :text
data/rdiscount.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rdiscount'
3
- s.version = '2.2.7.3'
3
+ s.version = '2.2.7.4'
4
4
  s.summary = "Fast Implementation of Gruber's Markdown in C"
5
5
  s.email = 'david@dafoster.net'
6
6
  s.homepage = 'http://dafoster.net/projects/rdiscount/'
@@ -21,6 +21,25 @@ class RDiscountTest < Test::Unit::TestCase
21
21
  RDiscount.new(text).to_html
22
22
  end
23
23
 
24
+ def test_that_oversized_input_raises_argument_error
25
+ # mkd_string() takes an int length, so inputs > INT_MAX (2 147 483 647 bytes)
26
+ # must be rejected before reaching C to avoid integer truncation / overflow.
27
+ int_max = 2_147_483_647 # INT_MAX in C
28
+ begin
29
+ oversized_text = 'a' * (int_max + 1)
30
+ # ArgumentError on TruffleRuby; RangeError on Windows
31
+ rescue NoMemoryError, ArgumentError, RangeError
32
+ # `omit` is Test::Unit's native skip; `skip` is Minitest's. Support both.
33
+ respond_to?(:omit, true) ?
34
+ omit("Insufficient memory to create oversized input for this test") :
35
+ skip("Insufficient memory to create oversized input for this test")
36
+ end
37
+
38
+ assert_raise(ArgumentError) do
39
+ RDiscount.new(oversized_text).to_html
40
+ end
41
+ end
42
+
24
43
  def test_that_smart_converts_double_quotes_to_curly_quotes
25
44
  rd = RDiscount.new(%("Quoted text"), :smart)
26
45
  assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>\n), rd.to_html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdiscount
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.7.3
4
+ version: 2.2.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -9,12 +9,10 @@ authors:
9
9
  - Andrew White
10
10
  - David Foster
11
11
  - l33tname
12
- autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2023-12-31 00:00:00.000000000 Z
14
+ date: 2026-04-02 00:00:00.000000000 Z
16
15
  dependencies: []
17
- description:
18
16
  email: david@dafoster.net
19
17
  executables:
20
18
  - rdiscount
@@ -80,7 +78,6 @@ homepage: http://dafoster.net/projects/rdiscount/
80
78
  licenses:
81
79
  - BSD-3-Clause
82
80
  metadata: {}
83
- post_install_message:
84
81
  rdoc_options: []
85
82
  require_paths:
86
83
  - lib
@@ -95,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
92
  - !ruby/object:Gem::Version
96
93
  version: '0'
97
94
  requirements: []
98
- rubygems_version: 3.2.3
99
- signing_key:
95
+ rubygems_version: 3.6.2
100
96
  specification_version: 4
101
97
  summary: Fast Implementation of Gruber's Markdown in C
102
98
  test_files: