-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Milestone
Description
Description
Problem
During addPieces, the SDK can throw:
undefined is not an object (evaluating 'value.length')
Wrapped as:
StorageContext addPieces failed: Failed to add piece to data set - undefined is not an object (evaluating 'value.length')
Cause
In packages/synapse-core/src/utils/metadata.ts, both pieceMetadataObjectToEntry and datasetMetadataObjectToEntry do:
for (const entry of entries) {
if (entry.key.length > METADATA_LIMITS.MAX_KEY_LENGTH) { ... }
if (entry.value.length > METADATA_LIMITS.MAX_VALUE_LENGTH) { // crashes if entry.value is undefinedMetadataObject is Record<string, string>, but that is not enforced at runtime. If any metadata entry has undefined as a value (e.g. from { key: undefined } or metadataInternal.ipfsRootCID being undefined), entry.value.length throws.
Impact
- Unhandled promise rejection can crash the server
- Upload to the storage provider succeeds, but the piece is not added to the data set
- File remains in S3; users can still view/sign, but pieces are not registered on-chain
Suggested fix
Validate entry.value before using it:
Either add null/undefined check like this:
for (const entry of entries) {
if (entry.key.length > METADATA_LIMITS.MAX_KEY_LENGTH) {
throw new Error('Metadata key exceeds the maximum length')
}
if (entry.value == null || String(entry.value).length > METADATA_LIMITS.MAX_VALUE_LENGTH) {
throw new Error('Metadata value exceeds the maximum length')
}
}Or filter invalid entries:
const entries = Object.entries(obj)
.filter(([, value]) => value != null && typeof value === 'string')
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([key, value]) => ({ key, value }))Will have to apply the same logic in both pieceMetadataObjectToEntry and datasetMetadataObjectToEntry.
Environment
@filoz/[email protected]@filoz/[email protected]
Reproduction
- Create a storage context with
metadata: { filosign_user: walletAddress } - Upload a piece with
metadata: {} - After the piece is uploaded to the SP,
addPiecesfails when processing the pending pieces batch
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
📌 Triage