From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_PASS,T_DKIM_INVALID, T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id A287120282 for ; Wed, 14 Jun 2017 21:56:18 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6BBA8120787; Thu, 15 Jun 2017 06:56:15 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id EE37A120784 for ; Thu, 15 Jun 2017 06:56:12 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=XTHvLw1iW3CHeBHgPwr8O14jy2Q=; b=fKd1kkS9Ssi/PSXy9b cwgP+NC59F2h53Pz6I3MOy7IduJ+X5tHL6mV8L+Xk3Tt1ZFWdGODcTf+Bdc0Akzg a+OzDzDBOhBA1MPEZF0OgDRvroEDWtOyQ7ptdztSU0tvNePBQ4eUNeugXReRSDt+ C4+3IrJlE7r+mkX6CdUx2msaU= Received: by filter1152p1mdw1.sendgrid.net with SMTP id filter1152p1mdw1-11331-5941B0F8-13 2017-06-14 21:56:08.34747944 +0000 UTC Received: from herokuapp.com (ec2-54-83-117-197.compute-1.amazonaws.com [54.83.117.197]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id f1U4ZEqbRuGj6YiBPsGohA for ; Wed, 14 Jun 2017 21:56:08.368 +0000 (UTC) Date: Wed, 14 Jun 2017 21:56:08 +0000 From: eregontp@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 56709 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13660 X-Redmine-Issue-Author: Eregon X-Redmine-Sender: Eregon X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS6nQwk96tQlF+EqSJy1ubix6AFyduszZQdCKQ I13BN+OEqPK7j4/7L7hD4H8dPRU6HukkQCfblULngqywj2OJPmI5BE4COOF6maOYVyiFmKk7GdKeDC Ebwtj7BC3Fx9nsVO5RSUZMg71SE/2ZL9cGaJdTEUqhzIi7Pi7ztTabQCyQ== X-ML-Name: ruby-core X-Mail-Count: 81681 Subject: [ruby-core:81681] [Ruby trunk Bug#13660] rb_str_hash_m discards bits from the hash X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #13660 has been reported by Eregon (Benoit Daloze). ---------------------------------------- Bug #13660: rb_str_hash_m discards bits from the hash https://bugs.ruby-lang.org/issues/13660 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- I believe rb_str_hash_m might discard some bits from the hash value in some situations. It computes the hash as a st_index_t, which is either a unsigned long or a unsigned long long. But the st_index_t value is converted to a VALUE with: #define ST2FIX(h) LONG2FIX((long)(h)) Note that for instance on x64-mingw32, SIZEOF_LONG is 4, but SIZEOF_LONG_LONG and SIZEOF_VOIDP are 8 bytes. So that truncates half the bits of the hash on such a platform if my understanding is correct. Even is SIZEOF_LONG is 8, LONG2FIX loses the MSB I think, given that not all long can fit the Fixnum range on MRI (should it be LONG2NUM?). Also, I am not sure if it is intended to cast from a unsigned value to a signed value. I tried many things while debugging the rb_str_hash spec on ruby/spec and eventually gave up. This computation looks wrong to me in MRI. For info, here is my debug code: https://github.com/eregon/rubyspec/blob/d62189450c0a56bfcd379e5e505ad097892d2bc7/optional/capi/string_spec.rb#L501-L518 https://github.com/eregon/rubyspec/blob/d62189450c0a56bfcd379e5e505ad097892d2bc7/optional/capi/ext/string_spec.c#L361-L381 and the build result on AppVeyor: https://ci.appveyor.com/project/eregon/spec-x948i/build/629 -- https://bugs.ruby-lang.org/