FuelLabs/fuel-core · error · Error::Serialization
Could not convert subsections_number to u16: {}
Error message
Could not convert subsections_number to u16: {} What it means
subsections_number counts how many pieces the uploaded bytecode was split into, stored as u16 in UploadBody. When the proto value does not fit u16 (> 65535 or negative), u16::try_from fails and this error aborts the Upload conversion.
Source
Thrown at crates/services/block_aggregator_api/src/blocks/old_block_source/convertor_adapter/proto_to_fuel_conversions.rs:784
))
})?;
let witness_index =
u16::try_from(proto_upload.witness_index).map_err(|e| {
Error::Serialization(anyhow!(
"Could not convert witness_index to u16: {}",
e
))
})?;
let subsection_index =
u16::try_from(proto_upload.subsection_index).map_err(|e| {
Error::Serialization(anyhow!(
"Could not convert subsection_index to u16: {}",
e
))
})?;
let subsections_number = u16::try_from(proto_upload.subsections_number)
.map_err(|e| {
Error::Serialization(anyhow!(
"Could not convert subsections_number to u16: {}",
e
))
})?;
let proof_set = proto_upload
.proof_set
.iter()
.map(|entry| {
Bytes32::try_from(entry.as_slice()).map_err(|e| {
Error::Serialization(anyhow!(
"Could not convert proof_set entry to Bytes32: {}",
e
))
})
})
.collect::<crate::result::Result<Vec<_>>>()?;
let body = UploadBody {View on GitHub (pinned to b9d4d170da)
Solutions
- Validate subsections_number <= 65535 (and >= 1) before converting; reject with the actual value in the message
- Fix the uploading client to use the chain-mandated subsection size so the count fits u16
- Cross-check subsection_index < subsections_number as part of the same pre-validation
- Round-trip test upload protos (encode→decode) in CI for both producer and consumer versions
Example fix
// before
let subsections_number = u16::try_from(proto_upload.subsections_number).map_err(...)?;
// after
let sn = proto_upload.subsections_number;
if !(1..=u16::MAX as u32).contains(&sn) {
return Err(anyhow!("subsections_number {sn} out of u16 range"));
}
let subsections_number = sn as u16; Defensive patterns
Strategy: validation
Validate before calling
fn upload_subsections_number_ok(u: &ProtoUpload) -> bool {
(1..=u16::MAX as u32).contains(&u.subsections_number)
} Type guard
fn valid_subsections_count(n: u32) -> bool { (1..=u16::MAX as u32).contains(&n) } Try / catch
let n = u16::try_from(u.subsections_number)
.with_context(|| format!("subsections_number {} invalid", u.subsections_number))?; Prevention
- Bound blob chunk counts by u16 in the uploader's chunking logic
- Reject zero subsection counts as malformed
- Keep upload parameter limits in one shared config, not duplicated constants
When it happens
Trigger: Producer encoded a subsections_number above 65535 — meaning the blob was chunked too finely (chunk size too small) — or garbage data reached the decoder.
Common situations: Chunk-size mismatch between uploader and chain rules; a client uploading a huge blob with 1-byte subsections as a bug; corrupted transport payloads.
Related errors
- Could not convert witness_index to u16: {}
- Could not convert subsection_index to u16: {}
- Could not convert upload root to Bytes32: {}
- Could not convert proof_set entry to Bytes32: {}
- Could not convert blob witness_index to u16: {}
AI-assisted analysis of FuelLabs/fuel-core@b9d4d170da (2026-08-16).
Data as JSON: /api/errors/f6b555b85fafb4d0.
Report an issue: GitHub.