@@ -307,22 +307,27 @@ class BaseBinaryBuilder
307
307
Status AppendBinaryWithLengths (std::string_view binary, const int32_t * value_lengths,
308
308
int64_t length) {
309
309
ARROW_RETURN_NOT_OK (Reserve (length));
310
- UnsafeAppendToBitmap (/* valid_bytes=*/ nullptr , length);
310
+ UnsafeAppendToBitmap (/* valid_bytes=*/ NULLPTR , length);
311
311
// All values is valid
312
312
int64_t accum_length = 0 ;
313
313
for (int64_t i = 0 ; i < length; ++i) {
314
314
accum_length += value_lengths[i];
315
315
}
316
- if (ARROW_PREDICT_FALSE (binary.size () < accum_length)) {
316
+ if (ARROW_PREDICT_FALSE (binary.size () < static_cast < size_t >( accum_length) )) {
317
317
return Status::Invalid (" Binary data is too short" );
318
318
}
319
+ if (ARROW_PREDICT_FALSE (binary.size () + value_data_builder_.length () >
320
+ std::numeric_limits<int32_t >::max ())) {
321
+ return Status::Invalid (" Append binary data too long" );
322
+ }
319
323
std::string_view sub_data = binary.substr (0 , accum_length);
320
324
ARROW_RETURN_NOT_OK (value_data_builder_.Append (
321
325
reinterpret_cast <const uint8_t *>(sub_data.data ()), sub_data.size ()));
322
326
accum_length = 0 ;
323
327
const int64_t initialize_offset = value_data_builder_.length ();
324
328
for (int64_t i = 0 ; i < length; ++i) {
325
- offsets_builder_.UnsafeAppend (initialize_offset + accum_length);
329
+ offsets_builder_.UnsafeAppend (
330
+ static_cast <int32_t >(initialize_offset + accum_length));
326
331
accum_length += value_lengths[i];
327
332
}
328
333
return Status::OK ();
@@ -331,18 +336,23 @@ class BaseBinaryBuilder
331
336
Status AppendBinaryWithLengths (std::string_view binary, const int32_t * value_lengths,
332
337
int64_t length, int64_t null_count,
333
338
const uint8_t * valid_bits, int64_t valid_bits_offset) {
334
- if (valid_bits == nullptr || null_count == 0 ) {
339
+ if (valid_bits == NULLPTR || null_count == 0 ) {
335
340
return AppendBinaryWithLengths (binary, value_lengths, length);
336
341
}
337
342
ARROW_RETURN_NOT_OK (Reserve (length));
338
343
int64_t accum_length = 0 ;
339
344
for (int64_t i = 0 ; i < length; ++i) {
340
345
accum_length += value_lengths[i];
341
346
}
342
- if (ARROW_PREDICT_FALSE (binary.size () < accum_length)) {
347
+ if (ARROW_PREDICT_FALSE (binary.size () < static_cast < size_t >( accum_length) )) {
343
348
return Status::Invalid (" Binary data is too short" );
344
349
}
345
350
const int64_t original_offset = value_data_builder_.length ();
351
+ if (ARROW_PREDICT_FALSE (original_offset + accum_length) >
352
+ std::numeric_limits<int32_t >::max ()) {
353
+ return Status::Invalid (" Append binary data too long" );
354
+ }
355
+
346
356
std::string_view sub_data = binary.substr (0 , accum_length);
347
357
ARROW_RETURN_NOT_OK (value_data_builder_.Append (
348
358
reinterpret_cast <const uint8_t *>(sub_data.data ()), sub_data.size ()));
@@ -351,13 +361,15 @@ class BaseBinaryBuilder
351
361
RETURN_NOT_OK (VisitNullBitmapInline (
352
362
valid_bits, valid_bits_offset, length, null_count,
353
363
[&]() {
354
- offsets_builder_.UnsafeAppend (original_offset + accum_length);
364
+ offsets_builder_.UnsafeAppend (
365
+ static_cast <int32_t >(original_offset + accum_length));
355
366
accum_length += value_lengths[length_idx];
356
367
++length_idx;
357
368
return Status::OK ();
358
369
},
359
370
[&]() {
360
- offsets_builder_.UnsafeAppend (original_offset + accum_length);
371
+ offsets_builder_.UnsafeAppend (
372
+ static_cast <int32_t >(original_offset + accum_length));
361
373
return Status::OK ();
362
374
}));
363
375
return Status::OK ();
0 commit comments