Skip to content

Fix Data Base64 length encoding bug #1425

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

Merged

Conversation

fabianfett
Copy link
Contributor

Motivation

We have an issue in encodeComputeCapacity. If we add lineBreaks, we assumed to add line breaks for lines that ended at the max capacity.

Changes

  • encodeComputeCapacity checks if the last line uses the full length and removes unnecessary seperatorBytes if needed

rdar://155204772

@parkera
Copy link
Contributor

parkera commented Jul 11, 2025

@swift-ci test

#expect(stringBase64 == String(decoding: dataBase64, as: Unicode.UTF8.self))
}

for count in 0..<10_000 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 10,000? If it takes a while to run and doesn’t provide additional code coverage it might be better to pick a lower number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed to 1_000 and parameterized the test:

􀟈 Test testBase64DataOutputMatchesStingOutput(options:) started.
􀟈 Test case passing 1 argument options → Base64EncodingOptions(rawValue: 33) to testBase64DataOutputMatchesStingOutput(options:) started.
􀟈 Test case passing 1 argument options → Base64EncodingOptions(rawValue: 17) to testBase64DataOutputMatchesStingOutput(options:) started.
􀟈 Test case passing 1 argument options → Base64EncodingOptions(rawValue: 2) to testBase64DataOutputMatchesStingOutput(options:) started.
􀟈 Test case passing 1 argument options → Base64EncodingOptions(rawValue: 0) to testBase64DataOutputMatchesStingOutput(options:) started.
􀟈 Test case passing 1 argument options → Base64EncodingOptions(rawValue: 1) to testBase64DataOutputMatchesStingOutput(options:) started.
​​​​​􁁛 Test testBase64DataOutputMatchesStingOutput(options:) with 5 test cases passed after 0.061 seconds.

@itingliu
Copy link
Contributor

Test failures are known and I just fixed/disabled those tests.

@itingliu
Copy link
Contributor

@swift-ci please test

### Motivation

We have an issue in encodeComputeCapacity. If we add lineBreaks, we assumed to add line breaks for lines that ended at the max capacity.

### Changes

- encodeComputeCapacity checks if the last line uses the full length and removes unnecessary seperatorBytes if needed

rdar://155204772
@fabianfett fabianfett force-pushed the ff-fix-base64-data-length-encoding-bug branch from 2b34d0c to 56dde3d Compare July 14, 2025 13:30
@parkera
Copy link
Contributor

parkera commented Jul 14, 2025

@swift-ci test

@itingliu itingliu merged commit 2d2e249 into swiftlang:main Jul 14, 2025
16 checks passed
@parkera
Copy link
Contributor

parkera commented Jul 14, 2025

Thanks @fabianfett

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.

3 participants