From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#58472: [PATCH] Make `message-unique-id' less prone to collisions Date: Wed, 12 Oct 2022 09:07:53 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0000000000006bf9d205ead89851" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12471"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Paul Eggert To: 58472@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 12 18:22:32 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oieV6-00030g-60 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 18:22:32 +0200 Original-Received: from localhost ([::1]:57932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieV4-0004aP-Qw for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 12:22:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieI3-0007qn-D8 for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 12:09:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59224) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oieI3-0006A6-4n for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 12:09:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oieI1-0001rS-OT; Wed, 12 Oct 2022 12:09:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: eggert@cs.ucla.edu, bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Oct 2022 16:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58472 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Paul Eggert Original-Received: via spool by submit@debbugs.gnu.org id=B.16655908967092 (code B ref -1); Wed, 12 Oct 2022 16:09:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Oct 2022 16:08:16 +0000 Original-Received: from localhost ([127.0.0.1]:58300 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oieHE-0001qG-Dn for submit@debbugs.gnu.org; Wed, 12 Oct 2022 12:08:16 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:60266) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oieH9-0001q5-W0 for submit@debbugs.gnu.org; Wed, 12 Oct 2022 12:08:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieH9-0005mZ-Pw for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 12:08:07 -0400 Original-Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]:43532) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oieGy-00065r-I9 for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 12:08:06 -0400 Original-Received: by mail-oo1-xc32.google.com with SMTP id m11-20020a4aab8b000000b00476743c0743so12438365oon.10 for ; Wed, 12 Oct 2022 09:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=zBDFGHfTa8szO7I9I+39KHC0wWw2AakX0Gsrg4lmyYI=; b=foK0T18xlRLSoTyW8SNlS0ezw7BZywnz/iy4RCPI/a1qnIn95TNLtgUg5JGThflwMT OaKkn18t5UENHK1S2IdJJvSvjZxcDmUyD8em2LW3JGkLDBV/uVBkQOCK6b4m6ZqcT++M 0O7Q9+vduGDfhXeH8hzmaHIkTsCr+yUEWuT/cVA5SouK3wQ5fYYOTecLm5XEs3o1MdSo hguxivZYPBs+Yz2TL+XB/LBiGc6Lk5viBeM8xCVCjY51v9vKfH/EfYe9qltCoGe69gIf PmNmplFq3FHa0rsQEonjI4Psx6YUQUUxzBAKYWN3ftHXEvyDmaljmR6pFdLeAv8jPBNi /e3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zBDFGHfTa8szO7I9I+39KHC0wWw2AakX0Gsrg4lmyYI=; b=zvh24GUqg8n2t/wzcx5ktYSp0awdDGr2FkL5II2UJmNi7kK1x49H6sg+Vl7meHGyuv f0/Ak7yYC0AzsMF0h/S+nmgx28knaPjT3l/Olgp+K3HI3WMQODHhs2NOy1AYNtNzvRNi GOV6ta4WfACCXbLkP5xhnub3dRm6b/BKna3KVm+TT9PicUTNMyiqAVeKuD/QS/Je0GOa W1axSRl3lhvQmFPkDlw0g6P6HL8/5jlfHkUZOqQxyYZrj3Wc2aZfOqKD8vmhlWj7hSqr 8WgT1HrYcCP0Jxh6NugLyIETxOL7ms8feEmIZIqaXAKrAjlJ5xRWLfAnWliSkEvfQKXN vpLg== X-Gm-Message-State: ACrzQf0KskvjXPKrHttPud6ndDP0e+mAogheUKkP+gt6oahnGfAgAMMO TJ1C6LbA5axH572hzCpoMsB5cxNcnFdVLf3ZYCn6wBkE X-Google-Smtp-Source: AMsMyM73fhvxOpC9YVK7aI1mXVpdkzPH0E1YxdhZGqxTxUJL9VaYKw/RIDhPsqia0sjSW+1Ovknm4jmj8KCarAv4haw= X-Received: by 2002:a9d:4003:0:b0:661:b434:7e95 with SMTP id m3-20020a9d4003000000b00661b4347e95mr3171144ote.224.1665590874593; Wed, 12 Oct 2022 09:07:54 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 12 Oct 2022 09:07:53 -0700 X-Hashcash: 1:20:221012:bug-gnu-emacs@gnu.org::LZjfxBwyO6HBlU6u:4yf8 Received-SPF: pass client-ip=2607:f8b0:4864:20::c32; envelope-from=stefankangas@gmail.com; helo=mail-oo1-xc32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:245230 Archived-At: --0000000000006bf9d205ead89851 Content-Type: text/plain; charset="UTF-8" This is a proposal to make `message-unique-id' less prone to collisions. For the first 1-2 characters, it uses the return value `user-uid', which on most single-user systems is a fixed value (for example, this gives us "87" on almost any single-user Debian machine).[1] It's also unnecessarily leaky of potentially privacy sensitive information. The next 8 characters are the current time, with some gymnastics to emulate support for a fractional part to seconds. This seems unnecessary now that, AFAIU, `time-convert' can do that for us portably (please correct me if I'm wrong, Paul). I suggest that we instead base the left-hand side of the Message-ID on: 1. (time-convert nil (expt 10 9)) 2. 2^N bits of pseudo random data (e.g. N=32) We can then ignore the effective user id, while significantly decreasing the risk of a Message-ID collision.[2] Currently, we get values like: (message-unique-id) => "87o7uhi3at.fsf" ; length 10 With the attached patch, we have instead: (message-unique-id) => "cnk29wgg1a4nvrpqcy.fsf" ; length ~22 Note also that `message-number-base36' uses a Caesar cipher for some reason: (message-number-base36 5 -1) => "u" ; expect "5" (message-number-base36 (expt 36 3) -1) => "yzzz" ; expect "1000" The patch fixes this also. I don't know if this change should be in NEWS or not. Footnotes: [1] Just for fun, you can search for 87 on https://en.wikipedia.org/wiki/Message-ID [2] See also: https://www.jwz.org/doc/mid.html --0000000000006bf9d205ead89851 Content-Type: text/x-diff; charset="US-ASCII"; name="0001-Make-message-unique-id-less-prone-to-collisions.patch" Content-Disposition: attachment; filename="0001-Make-message-unique-id-less-prone-to-collisions.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: 42bc85781fc6ac22_0.1 RnJvbSA1ZWVkZjg4YmI4NWU1YjRhOGExYmI1NTZkODU2MzI0YWE5MzMzMDQyIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBTdGVmYW4gS2FuZ2FzIDxzdGVmYW5rYW5nYXNAZ21haWwuY29t PgpEYXRlOiBXZWQsIDEyIE9jdCAyMDIyIDE3OjI5OjA0ICswMjAwClN1YmplY3Q6IFtQQVRDSF0g TWFrZSBgbWVzc2FnZS11bmlxdWUtaWQnIGxlc3MgcHJvbmUgdG8gY29sbGlzaW9ucwoKKiBsaXNw L2dudXMvbWVzc2FnZS5lbCAobWVzc2FnZS11bmlxdWUtaW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