Skip to content

AWSSDK.DynamoDBv2 does not detect self-references in PutItem request #3722

Closed as not planned
@OleksandrKrutykh

Description

@OleksandrKrutykh

Describe the bug

If the item passed into Amazon.DynamoDBv2.AmazonDynamoDBClient.PutItemAsync method contains an AttributeValue with a self-reference, the method call results in a StackOverflowException. Since this exception cannot be caught, I assume it will crash whatever runtime environment the code is running in.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The call results in AmazonDynamoDBException or one of its inheritors.

Current Behavior

A StackOverflowException is thrown. Please, see the stack trace in ExceptionStack.txt attached. Note that the stack trace has been shortened for readability, because it contained a lot of identical AttributeValueMarshaller.Marshall calls.

ExceptionStack.txt

Reproduction Steps

Assuming that we have a DynamoDB table with a numeric hash key attribute called Id:

using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;

using var dynamoDbClient = new AmazonDynamoDBClient();

// An attribute value with a self-reference
var badItem = new Dictionary<string, AttributeValue>();
badItem["C"] = new AttributeValue { M = badItem };

var request = new PutItemRequest
{
    TableName = "<Table name here>",
    Item = new Dictionary<string, AttributeValue>
    {
        ["Id"] = new AttributeValue { N = "1" },
        ["Data"] = new AttributeValue { M = badItem }
    }
};

await dynamoDbClient.PutItemAsync(request);

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.DynamoDBv2 3.7.406.7

Targeted .NET Platform

.NET 8

Operating System and version

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.dynamodbp3This is a minor priority issuequeuedsEffort estimation: small

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions