Skip to content

Rework memory BIOs and implement BIO_seek (2nd try) #2433

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nhatnghiho
Copy link
Contributor

@nhatnghiho nhatnghiho commented May 22, 2025

Issues:

Resolves #CryptoAlg-3111

Description of changes:

Same as #2380.

Fixed the state bug that was causing Ruby failures. The failures came from BIO_reset, which tries to "rewind" the R/O buffer to its original state. The old implementation only works when the buffer pointer and read pointer are aligned. But in the new memory BIO, this is not always the case. The buffer pointer (b->data) does not need to align with the read pointer (since we can have a positive bbm->read_off). Our tests didn't cover this because the buffer pointer was synced with read pointer after every test case.

Testing:

Added tests for BIO_reset and BIO_seek functions that attempt to rewind the buffer internally. The tests cover both cases -- when buffer pointer and read pointer are synced and when they are not.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

nhatnghiho and others added 2 commits May 21, 2025 22:57
### Issues:
Resolves #CryptoAlg-3111

### Description of changes: 
This PR creates a wrapper around `BUF_MEM` and adds a new field `off` to
indicate the current offset of the read pointer. This enables us to
implement `BIO_seek`, which is also in this PR.

### Testing:
Unit tests are modified and added to cover more test cases.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
@nhatnghiho nhatnghiho requested a review from a team as a code owner May 22, 2025 02:45
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions


BIO *BIO_new_mem_buf(const void *buf, ossl_ssize_t len) {
BIO *ret;
BUF_MEM *b;
const size_t size = len < 0 ? strlen((char *)buf) : (size_t)len;
BIO_BUF_MEM *bbm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'bbm' is not initialized [cppcoreguidelines-init-variables]

Suggested change
BIO_BUF_MEM *bbm;
BIO_BUF_MEM *bbm = NULL;

@codecov-commenter
Copy link

codecov-commenter commented May 22, 2025

Codecov Report

Attention: Patch coverage is 93.81443% with 6 lines in your changes missing coverage. Please review.

Project coverage is 78.89%. Comparing base (f0b4afe) to head (4c2b05d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crypto/bio/bio_mem.c 90.32% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2433      +/-   ##
==========================================
+ Coverage   78.88%   78.89%   +0.01%     
==========================================
  Files         621      621              
  Lines      108547   108671     +124     
  Branches    15406    15420      +14     
==========================================
+ Hits        85623    85738     +115     
- Misses      22256    22261       +5     
- Partials      668      672       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

justsmth
justsmth previously approved these changes May 22, 2025
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 this pull request may close these issues.

4 participants