File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -324,7 +324,18 @@ _bson_append_va (bson_t *bson, /* IN */
324324
325325 buf = _bson_data (bson ) + bson -> len - 1 ;
326326
327+ /* Track running sum of bytes written in a uint64_t to detect possible overflow of `n_bytes`. */
328+ uint64_t n_bytes_sum = 0 ;
327329 do {
330+ // Size of any individual data being appended should not exceed the total byte limit.
331+ if (BSON_UNLIKELY (bson_cmp_less_uu (n_bytes , data_len ))) {
332+ return false;
333+ }
334+ // Total size of data being appended should not exceed the total byte limit.
335+ if (BSON_UNLIKELY (bson_cmp_greater_uu (n_bytes_sum , n_bytes - data_len ))) {
336+ return false;
337+ }
338+ n_bytes_sum += data_len ;
328339 n_pairs -- ;
329340 /* data may be NULL if data_len is 0. memcpy is not safe to call with
330341 * NULL. */
You can’t perform that action at this time.
0 commit comments