MCPcopy Create free account
hub / github.com/apache/avro-rs / test_avro_3448_recursive_definition_decode_array

Function test_avro_3448_recursive_definition_decode_array

avro/src/decode.rs:531–577  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

529 assert!(
530 result.is_err(),
531 "a huge array<long> block count must be rejected, got {result:?}"
532 );
533
534 Ok(())
535 }
536
537 #[test]
538 fn test_decode_map_huge_count_is_rejected() -> TestResult {
539 let payload = create_block(200_000_000);
540 let result = decode(&Schema::map(Schema::Long).build(), &mut payload.as_slice());
541 assert!(
542 result.is_err(),
543 "a huge map block count must be rejected, got {result:?}"
544 );
545
546 Ok(())
547 }
548
549 #[test]
550 fn test_decode_small_array_of_null_still_decodes() -> TestResult {
551 // A modest array of nulls within the budget must still decode.
552 let payload = create_block(3);
553 let result = decode(
554 &Schema::array(Schema::Null).build(),
555 &mut payload.as_slice(),
556 )?;
557 assert_eq!(Array(vec!(Value::Null, Value::Null, Value::Null)), result);
558
559 Ok(())
560 }
561
562 #[test]
563 fn avro_rs_639_test_nested_collections_share_one_allocation_budget() -> TestResult {
564 use crate::util::{DEFAULT_MAX_ALLOCATION_BYTES, max_allocation_bytes};
565
566 // Each inner array<null> block passes the per-collection check on its
567 // own, but the shared per-datum budget must reject the cumulative
568 // total: elements of type null cost zero wire bytes, so without a
569 // cumulative budget a handful of ~10-byte inner arrays would pin an
570 // unbounded multiple of the allocation limit in memory at once.
571 let budget = max_allocation_bytes(DEFAULT_MAX_ALLOCATION_BYTES);
572 let inner_count = (budget / 2) / size_of::<Value>() + 1;
573
574 let inner_arrays_count = 2;
575 let mut payload = Vec::new();
576 // Outer array: a single block declaring two inner arrays.
577 crate::util::zig_i64(inner_arrays_count, &mut payload)?;
578 for _ in 0..inner_arrays_count {
579 payload.extend(create_block(inner_count as i64));
580 }

Callers

nothing calls this directly

Calls 3

RecordClass · 0.85
encodeFunction · 0.85
successFunction · 0.85

Tested by

no test coverage detected