bson 4.8.2 → 4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/bson/bson-endian.h +1 -1
- data/ext/bson/bson-native.h +1 -1
- data/ext/bson/bytebuf.c +1 -1
- data/ext/bson/endian.c +1 -1
- data/ext/bson/init.c +1 -1
- data/ext/bson/read.c +67 -19
- data/ext/bson/util.c +1 -1
- data/ext/bson/write.c +1 -1
- data/lib/bson.rb +1 -1
- data/lib/bson/active_support.rb +1 -1
- data/lib/bson/array.rb +7 -2
- data/lib/bson/binary.rb +1 -1
- data/lib/bson/boolean.rb +9 -2
- data/lib/bson/code.rb +1 -1
- data/lib/bson/code_with_scope.rb +9 -2
- data/lib/bson/config.rb +1 -1
- data/lib/bson/date.rb +1 -1
- data/lib/bson/date_time.rb +1 -1
- data/lib/bson/decimal128.rb +1 -1
- data/lib/bson/decimal128/builder.rb +1 -1
- data/lib/bson/document.rb +1 -1
- data/lib/bson/environment.rb +2 -1
- data/lib/bson/error.rb +4 -0
- data/lib/bson/ext_json.rb +1 -1
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +1 -1
- data/lib/bson/hash.rb +7 -2
- data/lib/bson/int32.rb +1 -1
- data/lib/bson/int64.rb +1 -1
- data/lib/bson/integer.rb +1 -1
- data/lib/bson/json.rb +1 -1
- data/lib/bson/max_key.rb +1 -1
- data/lib/bson/min_key.rb +1 -1
- data/lib/bson/nil_class.rb +1 -1
- data/lib/bson/object.rb +1 -1
- data/lib/bson/object_id.rb +1 -1
- data/lib/bson/open_struct.rb +1 -1
- data/lib/bson/regexp.rb +1 -1
- data/lib/bson/registry.rb +1 -1
- data/lib/bson/specialized.rb +1 -1
- data/lib/bson/string.rb +1 -1
- data/lib/bson/symbol.rb +1 -1
- data/lib/bson/time.rb +1 -1
- data/lib/bson/time_with_zone.rb +1 -1
- data/lib/bson/timestamp.rb +1 -1
- data/lib/bson/true_class.rb +1 -1
- data/lib/bson/undefined.rb +1 -1
- data/lib/bson/version.rb +2 -2
- data/spec/bson/array_spec.rb +1 -1
- data/spec/bson/binary_spec.rb +1 -1
- data/spec/bson/binary_uuid_spec.rb +1 -1
- data/spec/bson/boolean_spec.rb +1 -1
- data/spec/bson/code_spec.rb +1 -1
- data/spec/bson/code_with_scope_spec.rb +1 -1
- data/spec/bson/date_spec.rb +1 -1
- data/spec/bson/date_time_spec.rb +1 -1
- data/spec/bson/decimal128_spec.rb +1 -1
- data/spec/bson/document_spec.rb +1 -1
- data/spec/bson/false_class_spec.rb +1 -1
- data/spec/bson/float_spec.rb +1 -1
- data/spec/bson/hash_spec.rb +1 -1
- data/spec/bson/int32_spec.rb +1 -1
- data/spec/bson/int64_spec.rb +1 -1
- data/spec/bson/integer_spec.rb +1 -1
- data/spec/bson/json_spec.rb +1 -1
- data/spec/bson/max_key_spec.rb +1 -1
- data/spec/bson/min_key_spec.rb +1 -1
- data/spec/bson/nil_class_spec.rb +1 -1
- data/spec/bson/object_id_spec.rb +1 -1
- data/spec/bson/object_spec.rb +1 -1
- data/spec/bson/open_struct_spec.rb +1 -1
- data/spec/bson/regexp_spec.rb +1 -1
- data/spec/bson/registry_spec.rb +1 -1
- data/spec/bson/string_spec.rb +1 -1
- data/spec/bson/symbol_spec.rb +1 -1
- data/spec/bson/time_spec.rb +1 -1
- data/spec/bson/time_with_zone_spec.rb +1 -1
- data/spec/bson/timestamp_spec.rb +1 -1
- data/spec/bson/true_class_spec.rb +1 -1
- data/spec/bson/undefined_spec.rb +1 -1
- data/spec/bson_spec.rb +1 -1
- data/spec/runners/common_driver.rb +1 -1
- data/spec/runners/corpus.rb +13 -10
- data/spec/runners/corpus_legacy.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/spec_tests/data/corpus/top.json +0 -4
- data/spec/support/shared_examples.rb +1 -1
- metadata +92 -115
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05c17fcaee2ceaefe97d801594460178acaf6a2f82c152ce33db819f01d624fa
|
4
|
+
data.tar.gz: 3343dfda6f4038fa261d077ddf860dd43ff001d2fbea7189110b6fa500fb2558
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7756cee7923f3ca584e6a1bfa3666f70d2f14804b3ddb913f0695be3495a061a632803a90d1cd87a63c95d5b9222c02b18fe475a38e2a8a680914819f90f4471
|
7
|
+
data.tar.gz: 88bf0b45ecbe2aa47c955ca5281568cbe6d48a4c144a5b49680f6f7d8684fa61524dcc80474118c12e9df13b6bfc4ffca1a0d0e55679c0325dcdfd48543aab96
|
data/README.md
CHANGED
@@ -38,7 +38,7 @@ As of 2.0.0, this project adheres to the
|
|
38
38
|
License
|
39
39
|
-------
|
40
40
|
|
41
|
-
Copyright (C) 2009-
|
41
|
+
Copyright (C) 2009-2020 MongoDB Inc.
|
42
42
|
|
43
43
|
Licensed under the Apache License, Version 2.0 (the "License");
|
44
44
|
you may not use this file except in compliance with the License.
|
data/ext/bson/bson-endian.h
CHANGED
data/ext/bson/bson-native.h
CHANGED
data/ext/bson/bytebuf.c
CHANGED
data/ext/bson/endian.c
CHANGED
data/ext/bson/init.c
CHANGED
data/ext/bson/read.c
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (C) 2009-
|
2
|
+
* Copyright (C) 2009-2020 MongoDB Inc.
|
3
3
|
*
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
* you may not use this file except in compliance with the License.
|
@@ -17,22 +17,28 @@
|
|
17
17
|
#include "bson-native.h"
|
18
18
|
#include <ruby/encoding.h>
|
19
19
|
|
20
|
-
static void
|
20
|
+
static void pvt_raise_decode_error(volatile VALUE msg);
|
21
|
+
static int32_t pvt_validate_length(byte_buffer_t *b);
|
21
22
|
static uint8_t pvt_get_type_byte(byte_buffer_t *b);
|
22
23
|
static VALUE pvt_get_int32(byte_buffer_t *b);
|
23
24
|
static VALUE pvt_get_int64(byte_buffer_t *b, int argc, VALUE *argv);
|
24
25
|
static VALUE pvt_get_double(byte_buffer_t *b);
|
25
|
-
static VALUE pvt_get_string(byte_buffer_t *b);
|
26
|
+
static VALUE pvt_get_string(byte_buffer_t *b, const char *data_type);
|
26
27
|
static VALUE pvt_get_symbol(byte_buffer_t *b, VALUE rb_buffer, int argc, VALUE *argv);
|
27
28
|
static VALUE pvt_get_boolean(byte_buffer_t *b);
|
28
29
|
static VALUE pvt_read_field(byte_buffer_t *b, VALUE rb_buffer, uint8_t type, int argc, VALUE *argv);
|
29
30
|
static void pvt_skip_cstring(byte_buffer_t *b);
|
30
31
|
|
32
|
+
void pvt_raise_decode_error(volatile VALUE msg) {
|
33
|
+
VALUE klass = pvt_const_get_3("BSON", "Error", "BSONDecodeError");
|
34
|
+
rb_exc_raise(rb_exc_new_str(klass, msg));
|
35
|
+
}
|
36
|
+
|
31
37
|
/**
|
32
38
|
* validate the buffer contains the amount of bytes the array / hash claimns
|
33
39
|
* and that it is null terminated
|
34
40
|
*/
|
35
|
-
|
41
|
+
int32_t pvt_validate_length(byte_buffer_t *b)
|
36
42
|
{
|
37
43
|
int32_t length;
|
38
44
|
|
@@ -53,6 +59,8 @@ void pvt_validate_length(byte_buffer_t *b)
|
|
53
59
|
else{
|
54
60
|
rb_raise(rb_eRangeError, "Buffer contained invalid length %d at %zu", length, b->read_position);
|
55
61
|
}
|
62
|
+
|
63
|
+
return length;
|
56
64
|
}
|
57
65
|
|
58
66
|
/**
|
@@ -64,7 +72,7 @@ VALUE pvt_read_field(byte_buffer_t *b, VALUE rb_buffer, uint8_t type, int argc,
|
|
64
72
|
case BSON_TYPE_INT32: return pvt_get_int32(b);
|
65
73
|
case BSON_TYPE_INT64: return pvt_get_int64(b, argc, argv);
|
66
74
|
case BSON_TYPE_DOUBLE: return pvt_get_double(b);
|
67
|
-
case BSON_TYPE_STRING: return pvt_get_string(b);
|
75
|
+
case BSON_TYPE_STRING: return pvt_get_string(b, "String");
|
68
76
|
case BSON_TYPE_SYMBOL: return pvt_get_symbol(b, rb_buffer, argc, argv);
|
69
77
|
case BSON_TYPE_ARRAY: return rb_bson_byte_buffer_get_array(argc, argv, rb_buffer);
|
70
78
|
case BSON_TYPE_DOCUMENT: return rb_bson_byte_buffer_get_hash(argc, argv, rb_buffer);
|
@@ -119,9 +127,20 @@ VALUE rb_bson_byte_buffer_get_bytes(VALUE self, VALUE i)
|
|
119
127
|
}
|
120
128
|
|
121
129
|
VALUE pvt_get_boolean(byte_buffer_t *b){
|
122
|
-
VALUE result
|
130
|
+
VALUE result;
|
131
|
+
char byte_value;
|
123
132
|
ENSURE_BSON_READ(b, 1);
|
124
|
-
|
133
|
+
byte_value = *READ_PTR(b);
|
134
|
+
switch (byte_value) {
|
135
|
+
case 1:
|
136
|
+
result = Qtrue;
|
137
|
+
break;
|
138
|
+
case 0:
|
139
|
+
result = Qfalse;
|
140
|
+
break;
|
141
|
+
default:
|
142
|
+
pvt_raise_decode_error(rb_sprintf("Invalid boolean byte value: %d", (int) byte_value));
|
143
|
+
}
|
125
144
|
b->read_position += 1;
|
126
145
|
return result;
|
127
146
|
}
|
@@ -134,22 +153,35 @@ VALUE rb_bson_byte_buffer_get_string(VALUE self)
|
|
134
153
|
byte_buffer_t *b;
|
135
154
|
|
136
155
|
TypedData_Get_Struct(self, byte_buffer_t, &rb_byte_buffer_data_type, b);
|
137
|
-
return pvt_get_string(b);
|
156
|
+
return pvt_get_string(b, "String");
|
138
157
|
}
|
139
158
|
|
140
|
-
VALUE pvt_get_string(byte_buffer_t *b)
|
159
|
+
VALUE pvt_get_string(byte_buffer_t *b, const char *data_type)
|
141
160
|
{
|
142
|
-
int32_t length;
|
143
161
|
int32_t length_le;
|
162
|
+
int32_t length;
|
163
|
+
char *str_ptr;
|
144
164
|
VALUE string;
|
165
|
+
unsigned char last_byte;
|
145
166
|
|
146
167
|
ENSURE_BSON_READ(b, 4);
|
147
|
-
memcpy(&
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
168
|
+
memcpy(&length_le, READ_PTR(b), 4);
|
169
|
+
length = BSON_UINT32_FROM_LE(length_le);
|
170
|
+
if (length < 0) {
|
171
|
+
pvt_raise_decode_error(rb_sprintf("String length is negative: %d", length));
|
172
|
+
}
|
173
|
+
if (length == 0) {
|
174
|
+
pvt_raise_decode_error(rb_str_new_cstr("String length is zero but string must be null-terminated"));
|
175
|
+
}
|
176
|
+
ENSURE_BSON_READ(b, 4 + length);
|
177
|
+
str_ptr = READ_PTR(b) + 4;
|
178
|
+
last_byte = *(READ_PTR(b) + 4 + length_le - 1);
|
179
|
+
if (last_byte != 0) {
|
180
|
+
pvt_raise_decode_error(rb_sprintf("Last byte of the string is not null: 0x%x", (int) last_byte));
|
181
|
+
}
|
182
|
+
rb_bson_utf8_validate(str_ptr, length - 1, true, data_type);
|
183
|
+
string = rb_enc_str_new(str_ptr, length - 1, rb_utf8_encoding());
|
184
|
+
b->read_position += 4 + length_le;
|
153
185
|
return string;
|
154
186
|
}
|
155
187
|
|
@@ -166,7 +198,7 @@ VALUE pvt_get_symbol(byte_buffer_t *b, VALUE rb_buffer, int argc, VALUE *argv)
|
|
166
198
|
VALUE value, klass;
|
167
199
|
|
168
200
|
if (pvt_get_mode_option(argc, argv) == BSON_MODE_BSON) {
|
169
|
-
value = pvt_get_string(b);
|
201
|
+
value = pvt_get_string(b, "Symbol");
|
170
202
|
klass = pvt_const_get_3("BSON", "Symbol", "Raw");
|
171
203
|
value = rb_funcall(klass, rb_intern("new"), 1, value);
|
172
204
|
} else {
|
@@ -306,10 +338,13 @@ VALUE rb_bson_byte_buffer_get_hash(int argc, VALUE *argv, VALUE self){
|
|
306
338
|
byte_buffer_t *b = NULL;
|
307
339
|
uint8_t type;
|
308
340
|
VALUE cDocument = pvt_const_get_2("BSON", "Document");
|
341
|
+
int32_t length;
|
342
|
+
char *start_ptr;
|
309
343
|
|
310
344
|
TypedData_Get_Struct(self, byte_buffer_t, &rb_byte_buffer_data_type, b);
|
311
345
|
|
312
|
-
|
346
|
+
start_ptr = READ_PTR(b);
|
347
|
+
length = pvt_validate_length(b);
|
313
348
|
|
314
349
|
doc = rb_funcall(cDocument, rb_intern("allocate"), 0);
|
315
350
|
|
@@ -318,6 +353,11 @@ VALUE rb_bson_byte_buffer_get_hash(int argc, VALUE *argv, VALUE self){
|
|
318
353
|
rb_hash_aset(doc, field, pvt_read_field(b, self, type, argc, argv));
|
319
354
|
RB_GC_GUARD(field);
|
320
355
|
}
|
356
|
+
|
357
|
+
if (READ_PTR(b) - start_ptr != length) {
|
358
|
+
pvt_raise_decode_error(rb_sprintf("Expected to read %d bytes for the hash but read %ld bytes", length, READ_PTR(b) - start_ptr));
|
359
|
+
}
|
360
|
+
|
321
361
|
return doc;
|
322
362
|
}
|
323
363
|
|
@@ -325,10 +365,13 @@ VALUE rb_bson_byte_buffer_get_array(int argc, VALUE *argv, VALUE self){
|
|
325
365
|
byte_buffer_t *b;
|
326
366
|
VALUE array = Qnil;
|
327
367
|
uint8_t type;
|
368
|
+
int32_t length;
|
369
|
+
char *start_ptr;
|
328
370
|
|
329
371
|
TypedData_Get_Struct(self, byte_buffer_t, &rb_byte_buffer_data_type, b);
|
330
372
|
|
331
|
-
|
373
|
+
start_ptr = READ_PTR(b);
|
374
|
+
length = pvt_validate_length(b);
|
332
375
|
|
333
376
|
array = rb_ary_new();
|
334
377
|
while((type = pvt_get_type_byte(b)) != 0){
|
@@ -336,5 +379,10 @@ VALUE rb_bson_byte_buffer_get_array(int argc, VALUE *argv, VALUE self){
|
|
336
379
|
rb_ary_push(array, pvt_read_field(b, self, type, argc, argv));
|
337
380
|
}
|
338
381
|
RB_GC_GUARD(array);
|
382
|
+
|
383
|
+
if (READ_PTR(b) - start_ptr != length) {
|
384
|
+
pvt_raise_decode_error(rb_sprintf("Expected to read %d bytes for the hash but read %ld bytes", length, READ_PTR(b) - start_ptr));
|
385
|
+
}
|
386
|
+
|
339
387
|
return array;
|
340
388
|
}
|
data/ext/bson/util.c
CHANGED
data/ext/bson/write.c
CHANGED
data/lib/bson.rb
CHANGED
data/lib/bson/active_support.rb
CHANGED
data/lib/bson/array.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -119,7 +119,8 @@ module BSON
|
|
119
119
|
buffer.get_array(**options)
|
120
120
|
else
|
121
121
|
array = new
|
122
|
-
buffer.
|
122
|
+
start_position = buffer.read_position
|
123
|
+
expected_byte_size = buffer.get_int32
|
123
124
|
while (type = buffer.get_byte) != NULL_BYTE
|
124
125
|
buffer.get_cstring
|
125
126
|
cls = BSON::Registry.get(type)
|
@@ -130,6 +131,10 @@ module BSON
|
|
130
131
|
end
|
131
132
|
array << value
|
132
133
|
end
|
134
|
+
actual_byte_size = buffer.read_position - start_position
|
135
|
+
if actual_byte_size != expected_byte_size
|
136
|
+
raise Error::BSONDecodeError, "Expected array to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
|
137
|
+
end
|
133
138
|
array
|
134
139
|
end
|
135
140
|
end
|
data/lib/bson/binary.rb
CHANGED
data/lib/bson/boolean.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -39,7 +39,14 @@ module BSON
|
|
39
39
|
#
|
40
40
|
# @since 2.0.0
|
41
41
|
def self.from_bson(buffer, **options)
|
42
|
-
buffer.get_byte
|
42
|
+
case v = buffer.get_byte
|
43
|
+
when TrueClass::TRUE_BYTE
|
44
|
+
true
|
45
|
+
when FalseClass::FALSE_BYTE
|
46
|
+
false
|
47
|
+
else
|
48
|
+
raise Error::BSONDecodeError, "Invalid boolean byte value: #{v}"
|
49
|
+
end
|
43
50
|
end
|
44
51
|
|
45
52
|
# Register this type when the module is loaded.
|
data/lib/bson/code.rb
CHANGED
data/lib/bson/code_with_scope.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -119,13 +119,20 @@ module BSON
|
|
119
119
|
#
|
120
120
|
# @since 2.0.0
|
121
121
|
def self.from_bson(buffer, **options)
|
122
|
-
|
122
|
+
# Code with scope has a length (?) field which is not needed for
|
123
|
+
# decoding, but spec tests want this field validated.
|
124
|
+
start_position = buffer.read_position
|
125
|
+
length = buffer.get_int32
|
123
126
|
javascript = buffer.get_string
|
124
127
|
scope = if options.empty?
|
125
128
|
::Hash.from_bson(buffer)
|
126
129
|
else
|
127
130
|
::Hash.from_bson(buffer, **options)
|
128
131
|
end
|
132
|
+
read_bytes = buffer.read_position - start_position
|
133
|
+
if read_bytes != length
|
134
|
+
raise Error::BSONDecodeError, "CodeWithScope invalid: claimed length #{length}, actual length #{read_bytes}"
|
135
|
+
end
|
129
136
|
new(javascript, scope)
|
130
137
|
end
|
131
138
|
|
data/lib/bson/config.rb
CHANGED
data/lib/bson/date.rb
CHANGED
data/lib/bson/date_time.rb
CHANGED
data/lib/bson/decimal128.rb
CHANGED
data/lib/bson/document.rb
CHANGED
data/lib/bson/environment.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -41,6 +41,7 @@ module BSON
|
|
41
41
|
# @return [ true, false ] If the Ruby version is 1.9.
|
42
42
|
#
|
43
43
|
# @since 4.2.0
|
44
|
+
# @deprecated
|
44
45
|
def ruby_1_9?
|
45
46
|
@ruby_1_9 ||= RUBY_VERSION < '2.0.0'
|
46
47
|
end
|
data/lib/bson/error.rb
CHANGED
data/lib/bson/ext_json.rb
CHANGED
data/lib/bson/false_class.rb
CHANGED
data/lib/bson/float.rb
CHANGED