-
Notifications
You must be signed in to change notification settings - Fork 527
ocr_bitmap can run out of buffer memory copying the "last font tag" #1586
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
ocr_bitmap can run out of buffer memory copying the "last font tag" #1586
Conversation
…nto qualip-ocr_bitmap-last_font_tag
…nto qualip-ocr_bitmap-last_font_tag
|
Hi @cfsmp3, the only Rust formatting issue that's left and I don't know how to fix is: Can you please enlighten me? |
|
You would need to use an unsafe block, because as the message error states, a race condition could arise. I believe, though it depends on if the C code is single threaded, which I haven't checked. |
…nto qualip-ocr_bitmap-last_font_tag
|
@wylited, thanks for the tip. Unfortunately, it doesn't solve the warning: diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs
index 8b014cd1..597e14e4 100644
--- a/src/rust/src/lib.rs
+++ b/src/rust/src/lib.rs
@@ -282,7 +282,10 @@ pub unsafe extern "C" fn ccxr_parse_parameters(argc: c_int, argv: *mut *mut c_ch
tlt_config = _tlt_config.to_ctype(&opt);
// Convert the rust struct (CcxOptions) to C struct (ccx_s_options), so that it can be used by the C code
- ccx_options.copy_from_rust(opt);
+ // safety: the C code is single-threaded and opt is locally scoped, so accessing `ccx_options` and `opt` is safe.^M
+ unsafe {^M
+ ccx_options.copy_from_rust(opt);^M
+ }^M
if !_capitalization_list.is_empty() {
capitalization_list = _capitalization_list.to_ctype();I did end up finding a solution which is to copy to a temporary ccx_options before assigning that copy to the static. See 6264d5b But, when I merged with latest master, someone already worked on fixing that issue by completely changing the C call to use a A couple more of my formatting fixes got lost in the merge. Oh well. (On second look, all of them :-( ) Please approve if this is up to code! |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
prateekmedia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
Looks like the CI - linux check's result never made it back to GH. It's still in pending state several days after completion. Can someone give it a nudge / restart it / bypass it? Let me know, |
In raising this pull request, I confirm the following (please check boxes):
My familiarity with the project is as follows (check one):
Version: 0.94
During OCR of a VOB PS, ccextractor can run out of buffer space if it has to copy all text since the last font tag (which can also be the beginning of the input):
I believe the bug existed since that piece of code was introduced way back in 2017 (#844)
The fix simply makes sure the allocated buffer is big enough for this extra string.
Example crash under gdb:
Before actually reaching this point I also had to fix an ASAN error with process_spu using
memcpyon overlapping buffers. I can't say I understand why the buffers would be overlapping but usingmemmoveat least fixes the error.