Skip to content

Fix undefined behavor in GenericStringArray::from_iter_values - #1145

Merged
alamb merged 4 commits into
apache:masterfrom
alamb:alamb/fix_undefined
Jan 10, 2022
Merged

alamb merged 4 commits into
apache:masterfrom
alamb:alamb/fix_undefined

Conversation

@alamb

@alamb alamb commented Jan 8, 2022

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #1144

Rationale for this change

If an iterator produces more values than its declared upper bound, it can result in undefined behavior

What changes are included in this PR?

Fix the bug by using the correct length

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jan 8, 2022
@alamb
alamb force-pushed the alamb/fix_undefined branch from 38a0af9 to db22383 Compare January 8, 2022 12:16
@alamb alamb changed the title Alamb/fix undefined Fix undefined behavor in GenericStringArray::from_iter_values Jan 8, 2022
@alamb

alamb commented Jan 8, 2022

Copy link
Copy Markdown
Contributor Author

I need to port my tests for this but I think the code is fine. I ran out of time today to keep working on this

@codecov-commenter

codecov-commenter commented Jan 8, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #1145 (13d6bac) into master (719096b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1145   +/-   ##
=======================================
  Coverage   82.55%   82.56%           
=======================================
  Files         169      169           
  Lines       50456    50497   +41     
=======================================
+ Hits        41655    41693   +38     
- Misses       8801     8804    +3     
Impacted Files Coverage Δ
arrow/src/array/array_string.rs 97.40% <100.00%> (+0.32%) ⬆️
arrow/src/util/test_util.rs 92.04% <100.00%> (+1.13%) ⬆️
arrow/src/datatypes/field.rs 53.79% <0.00%> (-0.31%) ⬇️
parquet_derive/src/parquet_field.rs 66.21% <0.00%> (-0.23%) ⬇️
arrow/src/array/transform/mod.rs 85.56% <0.00%> (-0.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 719096b...13d6bac. Read the comment docs.

Comment thread arrow/src/array/array_string.rs Outdated

// iterator size hint may not be correct so compute the actual number of offsets
let actual_len = match offsets.len() {
0 => 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We always push at least one offset (zero), so this match should not be needed. Looks good otherwise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jhorstmann -- I'll change this to assert len > 0 and try and polish up this PR with tests tomorrow

}

// iterator size hint may not be correct so compute the actual number of offsets
assert!(!offsets.is_empty()); // wrote at least one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

here is the fix -- the rest of the PR is tests

@alamb
alamb merged commit 35b04ca into apache:master Jan 10, 2022
@alamb
alamb deleted the alamb/fix_undefined branch January 10, 2022 21:47
@alamb alamb added the security label Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect

4 participants