Skip to content

Primitaint: Inconsistent behavior in switch-cases#5

Merged
tmbrbr merged 1 commit into
tmbrbr:primitaint-mergefrom
0drai:primitaint-fix-switch-case
Aug 5, 2024
Merged

Primitaint: Inconsistent behavior in switch-cases#5
tmbrbr merged 1 commit into
tmbrbr:primitaint-mergefrom
0drai:primitaint-fix-switch-case

Conversation

@0drai

@0drai 0drai commented Aug 4, 2024

Copy link
Copy Markdown

While switch-cases are typically strictly checked, they are optimized for small integer constants.

This results in the following inconsistency:

switch (Number.tainted(1234567)) {
  case 1234567:
    console.log("1"); // prints 1
    break;
  default:
    console.log("0");
    break;
}
switch (Number.tainted(1)) {
  case 1:
    console.log("1");
    break;
  default:
    console.log("0"); // prints 0
    break;
}

My approach to resolving this issue (akin to af544cf) is to check for taints in the discriminant and unbox it if necessary.

@0drai 0drai changed the title Primitaint: fixed optimized switch cases with tainted discriminants Primitaint: Inconsistent behavior in switch-cases Aug 4, 2024

@tmbrbr tmbrbr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good catch, the fix looks good!

@tmbrbr tmbrbr merged commit 64e50a2 into tmbrbr:primitaint-merge Aug 5, 2024
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.

2 participants