Skip to content
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

ERL-690: #Ref ordering is broken due to signed cast #3874

Closed
OTP-Maintainer opened this issue Aug 3, 2018 · 4 comments
Closed

ERL-690: #Ref ordering is broken due to signed cast #3874

OTP-Maintainer opened this issue Aug 3, 2018 · 4 comments
Assignees
Labels
bug Issue is reported as a bug priority:medium team:VM Assigned to OTP team VM
Milestone

Comments

@OTP-Maintainer
Copy link

Original reporter: dotsimon.
Affected version: OTP-21.0
Fixed in versions: OTP-20.3.8.5, OTP-21.0.5, OTP-19.3.6.10
Component: erts
Migrated from: https://bugs.erlang.org/browse/ERL-690


#Ref ordering is broken in all versions since at least R13B03 (the earliest in github). It does work in R12B03.

The comparison takes the difference of two Uint32 and casts it to Sint32 which is the wrong thing to do. For example, 2200000000 - 1 is positive, but sadly (Sint32)(22000000000-1) is negative.

The scary thing here is that it can make terms "invisible" in ets or Mnesia ram_copies or disc_copies tables.

I will submit a PR with test cases and a fix for this today.

{{    W2s = [610350147,899574699,2994196869,686384822,2397690439, 923302211],
    ExtRefBase = <<131,114,0,3,100,0,3,110,64,98,3>>,
    ExtRefs = [<<ExtRefBase/binary, 1:32, W2:32, 0:32>> || W2 <- W2s],
    Refs = [binary_to_term(Bin) || Bin <- ExtRefs],

    Ets = ets:new(refbug, [ordered_set]),
    ets:insert(Ets, [{Ref,Ref} || Ref <- Refs]),
    0 = length([R || R<-ets:tab2list(Ets), ets:lookup(Ets, element(1,R)) == []]),
    ok.
}}
@OTP-Maintainer
Copy link
Author

dotsimon. said:

Can anyone explain to me why the preformatted markdown didn't work?

@OTP-Maintainer
Copy link
Author

anders said:

The double-brace notation only works on a single line (I think). For a block you can use {{{noformat\}}} or {{{code\}}}.

https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=all

{code:erlang}
W2s = [610350147,899574699,2994196869,686384822,2397690439, 923302211],
ExtRefBase = <<131,114,0,3,100,0,3,110,64,98,3>>,
ExtRefs = [<<ExtRefBase/binary, 1:32, W2:32, 0:32>> || W2 <- W2s],
Refs = [binary_to_term(Bin) || Bin <- ExtRefs],

Ets = ets:new(refbug, [ordered_set]),
ets:insert(Ets, [{Ref,Ref} || Ref <- Refs]),
0 = length([R || R <- ets:tab2list(Ets), ets:lookup(Ets, element(1,R)) == []]),
ok.
{code}

@OTP-Maintainer
Copy link
Author

rickard said:

Thanks for fix and test-cases! These have been merged into the {{maint}} branch now.

@OTP-Maintainer
Copy link
Author

rickard said:

Patches for OTP 19, 20, and 21 including this fix are on the way out as well.

@OTP-Maintainer OTP-Maintainer added bug Issue is reported as a bug team:VM Assigned to OTP team VM priority:medium labels Feb 10, 2021
@OTP-Maintainer OTP-Maintainer added this to the OTP-20.3.8.5 milestone Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug priority:medium team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

2 participants