appsmithorg / appsmith

Platform to build admin panels, internal tools, and dashboards. Integrates with 25+ databases and any API.
https://www.appsmith.com
Apache License 2.0
33.83k stars 3.65k forks source link

[Bug]: Logic in GetDynamicStringSegments function does not split string segments correctly when processing binary data which leads to exceptions during REST API queries #29150

Open belleny90 opened 9 months ago

belleny90 commented 9 months ago

Is there an existing issue for this?

Description

Hi,

We are trying to upload binary zip-files via a FilePicker Widget which triggers a PUT Query for this. Here, we noticed (at that point) "arbitrary" exceptions thrown when trying to upload certain zip files, which could be tracked back to the URL being set to "null" when trying to execute the query. After digging a bit deeper using the browsers console I was able to track the error back to the function "GetDynamicStringSegments" in the file: app/client/src/utils/DynamicBindingUtils.ts.

The reason for this is, that the implemented logic is counting the number of opened and closed curly brackets "{", ”}" in order to separate json objects into string segments. Unfortunately, the binary data might also contain these characters and therefore can lead to a wrong segmentation of the json objects. Whether or not the segmentation will be corrupted is dependent on the ratio of opened and closed curly brackets and therefore seemed arbitrary to us at first.

The wrong segmentation then caused that the resulting corrupt json object containing the request parameters could not be parsed properly and the function returned "null" for the url and the data used for the API REST query.

Here is a screenshot where above mentioned is visible, as the variable "sum" counting opened and closed brackets has the value -3 due to the binary zip-file data containing multiple "}" characters, but is expected to be >=0:

Bildschirmfoto 2023-11-21 um 16 42 12

Steps To Reproduce

  1. Create a Filepicker for binary data which triggers a REST API query
  2. Upload a zip file which is decoded including the chars "{", ”}"
  3. Upload might fail because parameters were not returned properly

Public Sample App

No response

Environment

Release

Issue video log

No response

Version

Community 1.9.34

Nikhil-Nandagopal commented 9 months ago

@belleny90 it's pretty awesome how you managed to debug this! @arunvjn could you have a look here?

Nikhil-Nandagopal commented 6 months ago

Bumping this issue up to prod because it should have made it's way there by now if it was not fixed