Skip to content
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

[API] ALTO renderer does not work if no input name is set. #3788

Closed
sunoru opened this issue Apr 11, 2022 · 1 comment · Fixed by #3789
Closed

[API] ALTO renderer does not work if no input name is set. #3788

sunoru opened this issue Apr 11, 2022 · 1 comment · Fixed by #3789

Comments

@sunoru
Copy link
Contributor

sunoru commented Apr 11, 2022

Environment

  • Tesseract Version: 5.1.0
  • Commit Number: tag 5.1.0
  • Platform: Linux 5.16.18-200.fc35.x86_64 #1 SMP PREEMPT Mon Mar 28 14:10:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Current Behavior:

There would raise a segmentation fault if I use the following APIs (in pseudo code):

api = TessbaseAPICreate()
TessBaseAPIInit3(API, nullptr, nullptr)
renderer = TessAltoRendererCreate(output_file)
TessResultRendererBeginDocument(renderer, "")
TessBaseAPISetImage2(api, image)

Expected Behavior:

No segmentation fault should be raised. The file name would be left empty in the output.

Suggested Fix:

The segmentation fault is caused by strlen(nullptr), so maybe we should check if input_file_ is nullptr before doing AppendString (here)? It could also be fixed if the API user calls TessBaseAPISetInputName every time before TessResultRendererBeginDocument, but I still think this should be counted as a bug.

BTW, it worked for tesseract v4. #2700 is where a related breaking change was introduced.

@sunoru
Copy link
Contributor Author

sunoru commented Apr 11, 2022

Oh, actually an empty input_file_ would also cause a segmentation fault, because api->GetInputName() returns nullptr for it. It can be easily fixed by checking input for AppendString.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant