Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • 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
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7898
Closed
Open
Issue created Nov 06, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][cpp-restsdk] Segmentation fault and error compilation when trying to receive binary data

Created by: tzickel

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When receiving an binary string as a result, the C++ resksdk generator does not allocate the HttpContent it returns to the user, causing a Segmentation fault.

autogen/api/DefaultApi.cpp

    .then([=](std::vector<unsigned char> localVarResponse)
    {
        std::shared_ptr<HttpContent> localVarResult; // <-- Here is the bug, there is no allocation for HttpContent.
        std::shared_ptr<std::stringstream> stream = std::make_shared<std::stringstream>(std::string(localVarResponse.begin(), localVarResponse.end()));
        localVarResult->setData(stream);
        return localVarResult;
    });

Another related bug, is that in the api/model dirs, if the code returns an HttpContent, it adds in autogen/api/DefaultApi.h:

#include "HttpContent.h"

Which is wrong, and should point to:

#include "../HttpContent.h"

instead.

openapi-generator version

The docker image openapitools/openapi-generator-cli:latest as of 5/11/2020 The docker image openapitools/openapi-generator-cli:v5.0.0-beta2

OpenAPI declaration file content or url
swagger: "2.0"
info:
  title: "test"
host: "localhost:8080"
paths:
  /GetBackBinaryData:
    get:
      operationId: "GetBackBinaryData"
      produces:
      - "application/octet-stream"
      responses:
        "200":
          description: "successful operation"
          schema:
            type: string
            format: binary
Generation Details

generate -i /local/bug.yaml -g cpp-restsdk -o /local/autogen

Steps to reproduce

Generate, try to call the:

api.getBackBinaryData().wait()
Related issues/PRs

None

Suggest a fix

A fix would be to construct the HttpContent being used.

But a better fix, since this might be large data involved is to remove all this code, and simply return the std::vector from the previous stage (it's not like any of HttpContent other properties are used in this code base anyhow). But if it's used maybe in OpenAPI 3, then maybe allow for it to maybe hold the original std::vector anyhow ?

Assignee
Assign to
Time tracking