yeptris 0.6.7.5 → 0.6.8.1

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: a084064bffdbce7ccb0461e1402e7a91331e530e71b9ad31967d82e6e5b751db
4
- data.tar.gz: 0e8c5b97a1e09ef1f3bc4672806b777d68260075536370eedc8b628513f439f8
3
+ metadata.gz: b263a55abf16d57caf2c85268f108dc87059f9188c21e1b2a622129a6a8056f9
4
+ data.tar.gz: dcd7ae19f1d52c9615d1d4dd169a632483e8bc40f6303f0f4591aff8b1684c30
5
5
  SHA512:
6
- metadata.gz: 9791fdedd1c2afc3588abb612a8b98bd8ae57f065aea74db052b49f46025dfa52c40acb60a2aebb12acb41a5d464a957185d4ee62e0a07b38e069fcc94d431b2
7
- data.tar.gz: 6e3931a4cd862b8e8061d9b0c999f73113e0f62e11952ae630abbfd42cbfd76dd3f935a52990ee94a646c319e391b24f379398b940a3ca3fc101084fa31fda9c
6
+ metadata.gz: 999a6efa21ae21f9defc24546fa66e083ae9cf95dde6e6d93266c5ad75542b7c1a2923d19bda028124c1f825e447ab4062faf44ba31d6bf1199447e51492d582
7
+ data.tar.gz: 13afb6d81ca5795279dcebd790b4fae32d3e41abff68faacc7510d20c6557d0d358fb1bd217feee8d95b7aeb21b7b36cfc6f0d7f21e31a5e92e6e97f1f5c1292
data/lib/yeptris/cbor.rb CHANGED
@@ -41,17 +41,26 @@ module Yeptris
41
41
  raise Error, "libyeptris has no CBOR support" unless available?
42
42
 
43
43
  items = []
44
+ pending_error = nil
44
45
  receiver = ::FFI::Function.new(:int, %i[pointer pointer size_t]) do |_ctx, item, _index|
45
46
  # the callback owns the item; materialize then free in place
46
- # (through the wrapper — the finalizer frees too)
47
- doc = ::Yeptris::Document.new(item)
48
- items << doc.root&.to_ruby
49
- doc.free
50
- 0
47
+ # (through the wrapper — the finalizer frees too). A raise
48
+ # inside an FFI callback leaves the return value undefined —
49
+ # abort the C iteration cleanly (nonzero) and re-raise after
50
+ begin
51
+ doc = ::Yeptris::Document.new(item)
52
+ items << doc.root&.to_ruby
53
+ doc.free
54
+ 0
55
+ rescue ::Exception => e # rubocop:disable Lint/RescueException
56
+ pending_error = e
57
+ 1
58
+ end
51
59
  end
52
60
  st = ::Yeptris::FFI.yeptris_cbor_decode_sequence(
53
61
  data, data.bytesize, strict ? STRICT : 0, receiver, nil, nil
54
62
  )
63
+ raise pending_error if pending_error
55
64
  raise ParseError, ::Yeptris::FFI.last_error_message if st.zero? && !data.empty?
56
65
 
57
66
  items
data/lib/yeptris.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Yeptris
4
4
  # The gem's version lives in the parent namespace's file — the last
5
5
  # internal require (yeptris/version) retired with it.
6
- VERSION = "0.6.7.5".freeze
6
+ VERSION = "0.6.8.1".freeze
7
7
  # The error hierarchy lives in THIS file (the parent namespace's
8
8
  # own file): nested constants do not trigger a parent-constant
9
9
  # autoload, and the law forbids internal requires — defining the
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(yeptris
6
- VERSION 0.6.7
6
+ VERSION 0.6.8
7
7
  DESCRIPTION "Ultra-fast YAML 1.2 parser, emitter and streamer in C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -560,17 +560,25 @@ static size_t cbor_size_item(cenc* e, uint32_t id) {
560
560
  /* mapping */
561
561
  uint32_t pairs = n->count / 2;
562
562
  sz += cbor_arg_bytes(pairs);
563
- cmap* cm = NULL;
563
+ /* hold the INDEX, not the pointer: sizing a child recurses into
564
+ * nested maps whose preps REALLOC e->maps (#152 — a held cmap*
565
+ * dangled and the next pair read walked freed memory; n>=11 of
566
+ * the depth-3 users shape crossed the 16->32 growth) */
567
+ size_t canon_mi = 0;
568
+ int canon = 0;
564
569
  if (e->canonical) {
565
570
  if (!cbor_canon_prepare(e, id, pairs)) {
566
571
  return 0;
567
572
  }
568
- cm = &e->maps[e->nmaps - 1];
573
+ canon_mi = e->nmaps - 1;
574
+ canon = 1;
569
575
  }
570
- if (cm != NULL) {
576
+ if (canon) {
571
577
  for (uint32_t p = 0; p < pairs && !e->failed; p++) {
578
+ const cmap* cm = &e->maps[canon_mi];
572
579
  sz += cbor_size_item(e, cm->child[cm->order[p] * 2]);
573
580
  if (!e->failed) {
581
+ cm = &e->maps[canon_mi];
574
582
  sz += cbor_size_item(e, cm->child[cm->order[p] * 2 + 1]);
575
583
  }
576
584
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7.5
4
+ version: 0.6.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.