-
Notifications
You must be signed in to change notification settings - Fork 865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWSSDK.DynamoDBv2 does not detect self-references in PutItem request #3722
Comments
@OleksandrKrutykh Good afternoon. Thanks for opening the issue. The issue is reproducible with the below stack trace: > AWSSDK.Core.dll!ThirdParty.Json.LitJson.JsonWriter.Put(string str) Line 200 C#
AWSSDK.Core.dll!ThirdParty.Json.LitJson.JsonWriter.PutString(string str) Line 225 C#
AWSSDK.Core.dll!ThirdParty.Json.LitJson.JsonWriter.WritePropertyName(string property_name) Line 515 C#
AWSSDK.DynamoDBv2.dll!Amazon.DynamoDBv2.Model.Internal.MarshallTransformations.AttributeValueMarshaller.Marshall(Amazon.DynamoDBv2.Model.AttributeValue requestObject, Amazon.Runtime.Internal.Transform.JsonMarshallerContext context) Line 92 C#
AWSSDK.DynamoDBv2.dll!Amazon.DynamoDBv2.Model.Internal.MarshallTransformations.AttributeValueMarshaller.Marshall(Amazon.DynamoDBv2.Model.AttributeValue requestObject, Amazon.Runtime.Internal.Transform.JsonMarshallerContext context) Line 102 C#
[The 1 frame(s) above this were repeated 1570 times]
AWSSDK.DynamoDBv2.dll!Amazon.DynamoDBv2.Model.Internal.MarshallTransformations.AttributeValueMarshaller.Marshall(Amazon.DynamoDBv2.Model.AttributeValue requestObject, Amazon.Runtime.Internal.Transform.JsonMarshallerContext context) Line 102 C#
AWSSDK.DynamoDBv2.dll!Amazon.DynamoDBv2.Model.Internal.MarshallTransformations.PutItemRequestMarshaller.Marshall(Amazon.DynamoDBv2.Model.PutItemRequest publicRequest) Line 148 C#
AWSSDK.DynamoDBv2.dll!Amazon.DynamoDBv2.Model.Internal.MarshallTransformations.PutItemRequestMarshaller.Marshall(Amazon.Runtime.AmazonWebServiceRequest input) Line 48 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.Marshaller.PreInvoke(Amazon.Runtime.IExecutionContext executionContext) Line 93 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.Marshaller.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 55 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.PipelineHandler.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 165 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.CallbackHandler.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 61 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.PipelineHandler.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 165 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 53 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.PipelineHandler.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 165 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.MetricsHandler.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 94 C#
AWSSDK.Core.dll!Amazon.Runtime.Internal.RuntimePipeline.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.IExecutionContext executionContext) Line 152 C#
AWSSDK.Core.dll!Amazon.Runtime.AmazonServiceClient.InvokeAsync<Amazon.DynamoDBv2.Model.PutItemResponse>(Amazon.Runtime.AmazonWebServiceRequest request, Amazon.Runtime.Internal.InvokeOptionsBase options, System.Threading.CancellationToken cancellationToken) Line 278 C#
AWSSDK.DynamoDBv2.dll!Amazon.DynamoDBv2.AmazonDynamoDBClient.PutItemAsync(Amazon.DynamoDBv2.Model.PutItemRequest request, System.Threading.CancellationToken cancellationToken) Line 4978 C# This is due to the infinite self-referential chain. I'm unsure on the scenario which represents data model which refers to itself, causing the above issue. Perhaps, such data models should be revisited if it is determined that these would cause such infinite self-referencing chain. Also, how is it expected to represent such a chain in DynamoDB table. It might be thoughtful to have logic in place to break the chain in case of such infinite loop and store the item. But it would have issues during deserialization process to back from DynamoDB table. Should we throw an exception for such scenario? Perhaps yes. Needs review with the team. |
Hello @ashishdhingra. A {
"Id": { "N": "1" }
"Data": {
"M": {
"C": {
"M": {
"C": { A piece of code that creates such a data model certainly has a bug and needs to be fixed. Because of that, I don't think it would make sense to try convert the data model to a piece of valid DynamoDB JSON by breaking the infinite loop somewhere, because it would only hide the bug in the calling code. From my perspective, it would be OK for the AWS SDK to throw an exception when called with such a data model. What is important is that this exception should not be a I did not stumble upon this issue because I had a piece of logic that produced a data model with self-references. I was just implementing a piece of business logic that had to recursively go through a data model before saving it to a DynamoDB. I added a guardrail to my code to prevent it from going into an infinite loop if the data model contained self-references and decided to check (out of curiosity) how the AWS SDK reacts to self-references. |
Describe the bug
If the item passed into
Amazon.DynamoDBv2.AmazonDynamoDBClient.PutItemAsync
method contains anAttributeValue
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
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 identicalAttributeValueMarshaller.Marshall
calls.ExceptionStack.txt
Reproduction Steps
Assuming that we have a DynamoDB table with a numeric hash key attribute called
Id
: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
The text was updated successfully, but these errors were encountered: