Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #1545
Closed
Open
Issue created Apr 27, 2021 by Administrator@rootContributor

serializeMsgPack to dinamically allocated buffer of size len falls short.

Created by: gnalbandian

Hi @bblanchon.

I am extensively using your library along with ESPASyncWebServer from @me-no-dev. Once a second I send to webSocket clients a stream of ~400bytes with data to update a web page data.

I am using a DynamicJsonBuffer to store all my data.

// data is serialized above this section
// buffer is defined above this section as well as len
// uint8_t* buffer = nullptr;
// size_t len = 0;

 if(ws.count())
            {
                len = measureMsgPack(jsonDoc);
                buffer = (uint8_t*)malloc(sizeof(uint8_t) * len);
                
                if(buffer)
                {
                    serializeMsgPack(jsonDoc, buffer, len); // **<- the issue relies here**
                }
            }

After successful buffer allocation and population, I send the data and free the buffer.

if(buffer)
    {
        ws.binaryAll(buffer, len);
        free(buffer);
        buffer = nullptr;
    }

When reading the received data, I found out one value is missing. MessagePack is correctly decoded by javascript client, and it parses fine as a json. It's just the value of a key that instead of showing its current value, it shows always 0. It's data type is int32_t

After many test i found that increasing by 1 the length of the buffer size, I receive all the data as it should. ie: serializeMsgPack(jsonDoc, buffer, len + 1); // **<- the issue relies here**

The following section has not been modified: ws.binaryAll(buffer, len); Never added +1

Unfortunately, applying this 'fix' leads to random crash, very likely because of buffer overflow, not sure thou. Can yo shed some light over here. Thanks @bblanchon

Assignee
Assign to
Time tracking