Skip to content

fix(BytesOp::Find): fix slice index overflow#82

Merged
dr-orlovsky merged 6 commits intoAluVM:masterfrom
6293:fix-fits-usize
Jun 26, 2023
Merged

fix(BytesOp::Find): fix slice index overflow#82
dr-orlovsky merged 6 commits intoAluVM:masterfrom
6293:fix-fits-usize

Conversation

@6293
Copy link
Contributor

@6293 6293 commented Jun 21, 2023

No description provided.

@6293 6293 force-pushed the fix-fits-usize branch from 92b89dd to 66bd8dd Compare June 21, 2023 08:13
src/isa/exec.rs Outdated
let mut count = 0usize;
for i in 0..r1.len() {
if r1[i..len] == r2[..len] {
for i in 0..(r1_len + 1).saturating_sub(r2_len) {
Copy link
Member

Choose a reason for hiding this comment

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

r1_len + 1 can also panic (in debug) or overflow (in release)

Copy link
Contributor Author

@6293 6293 Jun 21, 2023

Choose a reason for hiding this comment

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

r1_len is at most u16::MAX (because it is ByteStr) stored as usize. so it will not overflow on +1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but I have to admit this is error prone. fixing it

@6293 6293 force-pushed the fix-fits-usize branch 2 times, most recently from a2f1e68 to 9ce67a5 Compare June 21, 2023 08:44
@6293 6293 force-pushed the fix-fits-usize branch from 9ce67a5 to b45b2c1 Compare June 21, 2023 08:46
@6293 6293 requested a review from dr-orlovsky June 21, 2023 08:47
@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2023

Codecov Report

Merging #82 (3a44520) into master (6682504) will increase coverage by 0.0%.
The diff coverage is 0.0%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@          Coverage Diff           @@
##           master     #82   +/-   ##
======================================
  Coverage    34.2%   34.2%           
======================================
  Files          19      19           
  Lines        4544    4541    -3     
======================================
  Hits         1554    1554           
+ Misses       2990    2987    -3     
Impacted Files Coverage Δ
src/isa/exec.rs 52.0% <0.0%> (+0.2%) ⬆️
src/isa/instr.rs 4.9% <0.0%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

};
f().unwrap_or_else(|| {
regs.st0 = false;
regs.set(RegA::A16, Reg32::Reg0, MaybeNumber::none());
Copy link
Member

Choose a reason for hiding this comment

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

Why are we removing this if the spec below says

If the first or the second string is `None`, sets `st0` to `false` and `a16[0]` to `None`.

Copy link
Contributor Author

@6293 6293 Jun 26, 2023

Choose a reason for hiding this comment

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

this is the spec for Find. The code here is for Rev. I thought this was accidentally copy-pasted from Find above

Copy link
Member

Choose a reason for hiding this comment

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

Yet still the Rev must reset the destination to the uninitialized state:

/// If the source string register is uninitialized, resets destination to the uninitialized

So I assume the above line should stay and be changed to

Suggested change
regs.set(RegA::A16, Reg32::Reg0, MaybeNumber::none());
regs.s16[reg2.as_usize()] = None;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true

@dr-orlovsky dr-orlovsky added the bug Something isn't working label Jun 26, 2023
@6293 6293 mentioned this pull request Jun 26, 2023
@6293 6293 requested a review from dr-orlovsky June 26, 2023 11:20
};
f().unwrap_or_else(|| {
regs.st0 = false;
regs.set(RegA::A16, Reg32::Reg0, MaybeNumber::none());
Copy link
Member

Choose a reason for hiding this comment

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

Yet still the Rev must reset the destination to the uninitialized state:

/// If the source string register is uninitialized, resets destination to the uninitialized

So I assume the above line should stay and be changed to

Suggested change
regs.set(RegA::A16, Reg32::Reg0, MaybeNumber::none());
regs.s16[reg2.as_usize()] = None;

@6293 6293 requested a review from dr-orlovsky June 26, 2023 13:03
Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

ACK 34b518a

@dr-orlovsky dr-orlovsky merged commit 9a7d77d into AluVM:master Jun 26, 2023
@dr-orlovsky dr-orlovsky added this to the 0.10.4 milestone Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants