Thread: BUG #4167: When generating UUID using UUID-OSSP module, UUIDs are not unique on Windows

The following bug has been logged online:

Bug reference:      4167
Logged by:          nicoanto
Email address:      na@mnm-consulting.com
PostgreSQL version: 8.3.1.0
Operating system:   Windows
Description:        When generating UUID using UUID-OSSP module, UUIDs are
not unique on Windows
Details:

Hi all,

I am using the 8.3.1 version of PostgreSQL. I wrote a simple function on
order to generate UUID values using the UUID-OSSP module
The code of the function is the following one :

    CREATE FUNCTION uuidgen() RETURNS CHAR(36) AS $$
       BEGIN
          RETURN uuid_generate_v4()::CHAR(36);
       END;
    $$ LANGUAGE 'plpgsql';



When using it in a loop, I have got 2 different behaviors :
* on an Ubuntu platform, the generated UUID values are unique
* on a Windows platform, the generated UUID values are not unique most of
the time.

Do you have any idea on how to fix that bug on a Windows platform ?

Regards,

Nicoanto
Am Mittwoch, 14. Mai 2008 schrieb nicoanto:
> I am using the 8.3.1 version of PostgreSQL. I wrote a simple function on
> order to generate UUID values using the UUID-OSSP module
> The code of the function is the following one :
>
>     CREATE FUNCTION uuidgen() RETURNS CHAR(36) AS $$
>        BEGIN
>           RETURN uuid_generate_v4()::CHAR(36);
>        END;
>     $$ LANGUAGE 'plpgsql';
>
>
>
> When using it in a loop, I have got 2 different behaviors :
> * on an Ubuntu platform, the generated UUID values are unique
> * on a Windows platform, the generated UUID values are not unique most of
> the time.
>
> Do you have any idea on how to fix that bug on a Windows platform ?

Congratulations, you have just independently rediscovered the Debian OpenSSL
vulnerability, see http://www.debian.org/security/2008/dsa-1571.  Get a new
libssl package from the Ubuntu security repository.  It's not a Windows bug;
the numbers are supposed to be different.
Peter Eisentraut wrote:
> Am Mittwoch, 14. Mai 2008 schrieb nicoanto:
> > I am using the 8.3.1 version of PostgreSQL. I wrote a simple function on
> > order to generate UUID values using the UUID-OSSP module
> > The code of the function is the following one :
> >
> >     CREATE FUNCTION uuidgen() RETURNS CHAR(36) AS $$
> >        BEGIN
> >           RETURN uuid_generate_v4()::CHAR(36);
> >        END;
> >     $$ LANGUAGE 'plpgsql';
> >
> >
> >
> > When using it in a loop, I have got 2 different behaviors :
> > * on an Ubuntu platform, the generated UUID values are unique
> > * on a Windows platform, the generated UUID values are not unique most of
> > the time.
> >
> > Do you have any idea on how to fix that bug on a Windows platform ?
>
> Congratulations, you have just independently rediscovered the Debian OpenSSL
> vulnerability, see http://www.debian.org/security/2008/dsa-1571.  Get a new
> libssl package from the Ubuntu security repository.  It's not a Windows bug;
> the numbers are supposed to be different.

Hmm, surely the problem is unrelated?  He gets the same numbers on
_Windows_, whereas Ubuntu shows the good behavior.

Also, OOSP-UUID does not depend on OpenSSL AFAIR.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
Peter Eisentraut wrote:
> Am Mittwoch, 14. Mai 2008 schrieb nicoanto:
>> I am using the 8.3.1 version of PostgreSQL. I wrote a simple function on
>> order to generate UUID values using the UUID-OSSP module
>> The code of the function is the following one :
>>
>>     CREATE FUNCTION uuidgen() RETURNS CHAR(36) AS $$
>>        BEGIN
>>           RETURN uuid_generate_v4()::CHAR(36);
>>        END;
>>     $$ LANGUAGE 'plpgsql';
>>
>>
>>
>> When using it in a loop, I have got 2 different behaviors :
>> * on an Ubuntu platform, the generated UUID values are unique
>> * on a Windows platform, the generated UUID values are not unique most of
>> the time.
>>
>> Do you have any idea on how to fix that bug on a Windows platform ?
>
> Congratulations, you have just independently rediscovered the Debian OpenSSL
> vulnerability, see http://www.debian.org/security/2008/dsa-1571.  Get a new
> libssl package from the Ubuntu security repository.  It's not a Windows bug;
> the numbers are supposed to be different.

I doubt that. There's no dependency from uuid library to openssl. And if
that was related, I would've expected to see non-unique values on
Ubuntu, not Windows.

Seems rather like a weakness in the Windows port of the ossp-uuid
library to me.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
Am Mittwoch, 14. Mai 2008 schrieb Alvaro Herrera:
> Hmm, surely the problem is unrelated?  He gets the same numbers on
> _Windows_, whereas Ubuntu shows the good behavior.

Oh, I read it backwards.  So then the random number generator on Windows is
the problem in this case.

> Also, OOSP-UUID does not depend on OpenSSL AFAIR.

Written by the same guy anyway. :-/
Peter Eisentraut wrote:
> Am Mittwoch, 14. Mai 2008 schrieb Alvaro Herrera:
> > Hmm, surely the problem is unrelated?  He gets the same numbers on
> > _Windows_, whereas Ubuntu shows the good behavior.
>
> Oh, I read it backwards.  So then the random number generator on Windows is
> the problem in this case.

Right.

Actually what I would suggest is using the Windows API for generating
UUIDs instead of OOSP-UUID.

> > Also, OOSP-UUID does not depend on OpenSSL AFAIR.
>
> Written by the same guy anyway. :-/

Oh, right ...

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
Peter Eisentraut <peter_e@gmx.net> writes:
> Am Mittwoch, 14. Mai 2008 schrieb Alvaro Herrera:
>> Hmm, surely the problem is unrelated?  He gets the same numbers on
>> _Windows_, whereas Ubuntu shows the good behavior.

> Oh, I read it backwards.  So then the random number generator on Windows is
> the problem in this case.

>> Also, OOSP-UUID does not depend on OpenSSL AFAIR.

> Written by the same guy anyway. :-/

Well, in any case this is surely a bug in the Windows port of
libossp-uuid, and so needs to be reported to them not us.

            regards, tom lane
Hi

Ahhh, This problem is reproduced. :-(
Sorry, I neglect it. Then, the following is considered as management.
http://winpg.jp/~saito/pg_work/OSSP_win32/getrand.c
I will consult to Ralf-san tonight. or weekend...

Regards,
Hiroshi Saito

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>


> Peter Eisentraut <peter_e@gmx.net> writes:
>> Am Mittwoch, 14. Mai 2008 schrieb Alvaro Herrera:
>>> Hmm, surely the problem is unrelated?  He gets the same numbers on
>>> _Windows_, whereas Ubuntu shows the good behavior.
>
>> Oh, I read it backwards.  So then the random number generator on Windows is
>> the problem in this case.
>
>>> Also, OOSP-UUID does not depend on OpenSSL AFAIR.
>
>> Written by the same guy anyway. :-/
>
> Well, in any case this is surely a bug in the Windows port of
> libossp-uuid, and so needs to be reported to them not us.
>
> regards, tom lane
Any news about a fix for this bug ?

Regards,

Nicolas ANTONINI

Hiroshi Saito a écrit :
> Hi
>
> Ahhh, This problem is reproduced. :-(
> Sorry, I neglect it. Then, the following is considered as management.
> http://winpg.jp/~saito/pg_work/OSSP_win32/getrand.c
> I will consult to Ralf-san tonight. or weekend...
>
> Regards,
> Hiroshi Saito
>
> ----- Original Message ----- From: "Tom Lane" <tgl@sss.pgh.pa.us>
>
>
>> Peter Eisentraut <peter_e@gmx.net> writes:
>>> Am Mittwoch, 14. Mai 2008 schrieb Alvaro Herrera:
>>>> Hmm, surely the problem is unrelated?  He gets the same numbers on
>>>> _Windows_, whereas Ubuntu shows the good behavior.
>>
>>> Oh, I read it backwards.  So then the random number generator on
>>> Windows is the problem in this case.
>>
>>>> Also, OOSP-UUID does not depend on OpenSSL AFAIR.
>>
>>> Written by the same guy anyway. :-/
>>
>> Well, in any case this is surely a bug in the Windows port of
>> libossp-uuid, and so needs to be reported to them not us.
>>
>> regards, tom lane
>
>


--
Nicolas ANTONINI
Directeur Technique
MNM Consulting
98, rue de Sèvres
75007 PARIS
T : + 33 (0)3 85 55 36 64
P : + 33 (0)6 23 71 85 24
Hi.

Sorry,  late reaction....Now, private time has only a few.
I will investigate at a weekend again.

Regards,
Hiroshi Saito

----- Original Message -----
From: "Nicolas ANTONINI" <nicolas.antonini@mnm-consulting.com>

> Any news about a fix for this bug ?
>
> Regards,
>
> Nicolas ANTONINI
>
> Hiroshi Saito a écrit :
>> Hi
>>
>> Ahhh, This problem is reproduced. :-(
>> Sorry, I neglect it. Then, the following is considered as management.
>> http://winpg.jp/~saito/pg_work/OSSP_win32/getrand.c
>> I will consult to Ralf-san tonight. or weekend...
>>
>> Regards,
>> Hiroshi Saito
>>
>> ----- Original Message ----- From: "Tom Lane" <tgl@sss.pgh.pa.us>
>>
>>
>>> Peter Eisentraut <peter_e@gmx.net> writes:
>>>> Am Mittwoch, 14. Mai 2008 schrieb Alvaro Herrera:
>>>>> Hmm, surely the problem is unrelated?  He gets the same numbers on
>>>>> _Windows_, whereas Ubuntu shows the good behavior.
>>>
>>>> Oh, I read it backwards.  So then the random number generator on Windows is the problem
>>>> in this case.
>>>
>>>>> Also, OOSP-UUID does not depend on OpenSSL AFAIR.
>>>
>>>> Written by the same guy anyway. :-/
>>>
>>> Well, in any case this is surely a bug in the Windows port of
>>> libossp-uuid, and so needs to be reported to them not us.
>>>
>>> regards, tom lane
>>
>>
>
>
> --
> Nicolas ANTONINI
> Directeur Technique
> MNM Consulting
> 98, rue de Sèvres
> 75007 PARIS
> T : + 33 (0)3 85 55 36 64
> P : + 33 (0)6 23 71 85 24
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

Re: BUG #4167: When generating UUID using UUID-OSSP module, UUIDs are not unique on Windows

From
"Ismael Ciordia, Openbravo"
Date:
Hi,

any progress on a fix for this bug?

Thanks,

Ismael Ciordia
Hi.

Yes,please see.!
http://winpg.jp/~saito/pg_work/OSSP_win32/

Regards,
Hiroshi Saito

>Hi,
>
>any progress on a fix for this bug?
>
>Thanks,
>
>Ismael Ciordia
>
>--
>Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-bugs

Re: BUG #4167: When generating UUID using UUID-OSSP module, UUIDs are not unique on Windows

From
"Ismael Ciordia, Openbravo"
Date:
Thanks!

Is it planned to include this fix in release 8.3.4? Is release 8.3.4
scheduled already?

Regards,

Ismael Ciordia

-----Mensaje original-----
De: Hiroshi Saito [mailto:z-saito@guitar.ocn.ne.jp]
Enviado el: viernes, 08 de agosto de 2008 14:34
Para: ismael.ciordia@openbravo.com
CC: pgsql-bugs@postgresql.org
Asunto: Re: [BUGS] BUG #4167: When generating UUID using UUID-OSSP
module, UUIDs are not unique on Windows


Hi.

Yes,please see.!
http://winpg.jp/~saito/pg_work/OSSP_win32/

Regards,
Hiroshi Saito

>Hi,
>
>any progress on a fix for this bug?
>
>Thanks,
>
>Ismael Ciordia
>
>--
>Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-bugs


--
No virus found in this incoming message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 270.5.12/1599 - Release Date: 07/08/2008
20:49
Hi.

----- Original Message -----
From: "Ismael Ciordia, Openbravo" <ismael.ciordia@openbravo.com>

> Thanks!
>
> Is it planned to include this fix in release 8.3.4? Is release 8.3.4
> scheduled already?

8.3.x will be made new since it has already contained the module.
However, the release schedule of 8.3.4 is not decided....sorry..

Regards,
Hiroshi Saito
Faithful record-keeping this ML(pgsql-bug).

Fixed the bug in both Windows and Ubuntu platforms.
It is uuid-ossp version 1.6.2.

Thanks!

Regards,
Hiroshi Saito

----- Original Message -----
From: "Ismael Ciordia, Openbravo" <ismael.ciordia@openbravo.com>
Subject: RE: [BUGS] BUG #4167: When generating UUID using UUID-OSSP module, UUIDs are not unique on
Windows


> Sure, no problem.
>
> Thanks again
>
> -----Mensaje original-----
> De: Hiroshi Saito [mailto:z-saito@guitar.ocn.ne.jp]
> Enviado el: miércoles, 12 de noviembre de 2008 16:37
> Para: Ismael Ciordia, Openbravo
> Asunto: Re: [BUGS] BUG #4167: When generating UUID using UUID-OSSP
> module, UUIDs are not unique on Windows
>
>
> Hi Ismael-san.
>
> No problem.
> good news will be comfortable.:-)
>
> P.S)
> May I act to pgsql-bug-ML as the forward of this report?
>
> Regards,
> Hiroshi Saito
>
> ----- Original Message -----
> From: "Ismael Ciordia, Openbravo" <ismael.ciordia@openbravo.com>
> To: "'Hiroshi Saito'" <z-saito@guitar.ocn.ne.jp>
> Sent: Thursday, November 13, 2008 12:26 AM
> Subject: RE: [BUGS] BUG #4167: When generating UUID using UUID-OSSP module,
> UUIDs are not unique on
> Windows
>
>
>> Hi Hiroshi-san,
>>
>> we have tested the problem in an Ubuntu box and it works perfectly. Sorry
>> for inconveniences, and thanks a lot for your support.
>>
>> Kind regards,
>>
>> Ismael
>>
>> -----Mensaje original-----
>> De: Hiroshi Saito [mailto:z-saito@guitar.ocn.ne.jp]
>> Enviado el: miércoles, 12 de noviembre de 2008 10:05
>> Para: Ismael Ciordia, Openbravo
>> Asunto: Re: [BUGS] BUG #4167: When generating UUID using UUID-OSSP
>> module, UUIDs are not unique on Windows
>>
>>
>> Hi Ismael-san.
>>
>> Is passing this problem information to pgsql-bug-ML allowed?
>> I think that this Ubuntu problem is suitable as shared information.
>>
>> Regards,
>> Hiroshi Saito
>>
>> ----- Original Message -----
>> From: "Ismael Ciordia, Openbravo" <ismael.ciordia@openbravo.com>
>> To: "'Hiroshi Saito'" <z-saito@guitar.ocn.ne.jp>
>> Sent: Wednesday, November 12, 2008 5:35 PM
>> Subject: RE: [BUGS] BUG #4167: When generating UUID using UUID-OSSP
> module,
>> UUIDs are not unique on
>> Windows
>>
>>
>>> Thanks a lot, Hiroshi-san. You have been very helpful. I will
> double-check
>>> the problem in Ubuntu.
>>>
>>> Regards,
>>>
>>> Ismael
>>>
>>> -----Mensaje original-----
>>> De: Hiroshi Saito [mailto:z-saito@guitar.ocn.ne.jp]
>>> Enviado el: miércoles, 12 de noviembre de 2008 2:23
>>> Para: Ismael Ciordia, Openbravo
>>> Asunto: Re: [BUGS] BUG #4167: When generating UUID using UUID-OSSP
>>> module, UUIDs are not unique on Windows
>>>
>>>
>>> Hi Ismael-san.
>>>
>>> The windows environment has already realized by special correction.
>>> Then, they are Ralf-san with me check ending and become 1.6.3/4
> following.
>>> http://winpg.jp/~saito/pg_work/OSSP_win32/
>>> Furthermore, the fixed version is built in pginstaller (8.3.5).
>>>
>>> However, It is not the Ubuntu environment........
>>> It may have the own problem of Ubuntu.
>>>
>>> Regards,
>>> Hiroshi Saito
>>>
>>> ----- Original Message -----
>>> From: "Ismael Ciordia, Openbravo" <ismael.ciordia@openbravo.com>
>>>
>>>
>>>> Hi Hiroshi-san,
>>>>
>>>> we are interested in fixing the bug in both Windows and Ubuntu
> platforms.
>>>>
>>>> It is not clear to me yet where the fix should be done (in the UUID-OSSP
>>>> module or at Operative System level). I would like to get in contact
> with
>>>> someone who could fix it in both platforms and guarantee that the fix
>> will
>>>> be included in the next PostgreSql public release to discuss with him
> how
>>> we
>>>> can sponsor the development.
>>>>
>>>> Is Ralf this person? If yes, how I could reach him? If not possible, is
>>>> there any other person who could do it?
>>>>
>>>> Thanks in advance for your help. Regards,
>>>>
>>>> Ismael
>>>>
>>>> -----Mensaje original-----
>>>> De: Hiroshi Saito [mailto:z-saito@guitar.ocn.ne.jp]
>>>> Enviado el: martes, 11 de noviembre de 2008 15:58
>>>> Para: Ismael Ciordia, Openbravo
>>>> Asunto: Re: [BUGS] BUG #4167: When generating UUID using UUID-OSSP
>>>> module, UUIDs are not unique on Windows
>>>>
>>>>
>>>> Hi Ismael-san.
>>>>
>>>> ----- Original Message -----
>>>> From: "Ismael Ciordia, Openbravo" <ismael.ciordia@openbravo.com>
>>>>
>>>>
>>>>> Hi Hiroshi,
>>>>>
>>>>> this is Ismael Ciordia from Openbravo. In the next release of Openbravo
>>>> ERP
>>>>> (2.50) we are doing extensive use of UUID. Is there any progress on
> this
>>>>> bug? We have experienced as well this bug in a linux (Ubuntu)
>>> environment,
>>>>> do you know if it is reported?
>>>>
>>>> It seems that some Ubuntu users are looking at the problem to be sure.
>>>> Probably, Ralf-san(OSSP project leader) is very busy now....
>>>>
>>>>>
>>>>> We have prepared an ugly work around to solve it (do a loop till
>>> generated
>>>>> ID changes from the last execution) but it is not gonna work in
>>> production
>>>>> environments.
>>>>>
>>>>> We are really interested in a fix to this bug included in the next
>>>>> PostgreSql release, and we would consider to sponsor this development
> if
>>>>> required.
>>>>
>>>> Ahh, sorry.. I don't have the environment of Ubuntu now.
>>>> My usual environment is win32, FreeBSD, and OpenSUSE.
>>>>
>>>
>>
>
Ooops, It will be helpful to a user.
Therefore,  it transmits here.:-)
Thanks!!

--  copy --
Hi Hiroshi-san,

if you want you can include the function we have used to test the problem,
pasted below.

Regards,

Ismael

**************

CREATE OR REPLACE FUNCTION test_uuidgen(countmax INTEGER) RETURNS character
varying AS
$BODY$
DECLARE
  countmin INTEGER := 1;
  distinctuuid bigint;
  v_message VARCHAR(2000) := '';

BEGIN
    drop table if exists uuid_gen;
    CREATE TABLE uuid_gen
    (
      uuid_gen_col uuid NOT NULL

    );
    LOOP
        INSERT INTO uuid_gen (uuid_gen_col) VALUES (uuid_generate_v1());
        countmin := countmin + 1;
        EXIT WHEN countmin > countmax;
    END LOOP;
    SELECT COUNT(DISTINCT uuid_gen_col) INTO distinctuuid FROM uuid_gen;
    IF distinctuuid <> countmax THEN
        v_message := 'Repeated UUID: FAILS';
    ELSE
        v_message := 'NO repeated UUID: OK';
    END IF;
    RETURN v_message;
END;
$BODY$  LANGUAGE 'plpgsql';
Hi.

Sorry,very late reaction...

Thanks!, It's a good information.:-)
and,CC to Ralf-san.

Regards,
Hiroshi Saito

>Hi Hiroshi-san,
>
>we have run our test in the next environments:
>-Windows XP + PostgreSql 8.3.5
>-Ubunto + PostgreSql 8.3.3
>
>In both cases the test was successful, so we have closed the topic.
>
>Thanks a lot for your support, PostgreSql is an incredible database.
>
>Kind regards,
>
>Ismael
>
>-----Mensaje original-----
>De: Hiroshi Saito [mailto:z-saito@guitar.ocn.ne.jp]
>Enviado el: mi$BqS(Bcoles, 12 de noviembre de 2008 17:15
>Para: pgsql-bugs@postgresql.org
>CC: Ismael Ciordia, Openbravo
>Asunto: Re: [BUGS] BUG #4167: When generating UUID using UUID-OSSP
>module, UUIDs are not unique on Windows
>
>
>Ooops, It will be helpful to a user.
>Therefore,  it transmits here.:-)
>Thanks!!
>
>--  copy --
>Hi Hiroshi-san,
>
>if you want you can include the function we have used to test the problem,
>pasted below.
>
>Regards,
>
>Ismael
>
>**************
>
>CREATE OR REPLACE FUNCTION test_uuidgen(countmax INTEGER) RETURNS character
>varying AS
>$BODY$
>DECLARE
>  countmin INTEGER := 1;
>  distinctuuid bigint;
>  v_message VARCHAR(2000) := '';
>
>BEGIN
>    drop table if exists uuid_gen;
>    CREATE TABLE uuid_gen
>    (
>      uuid_gen_col uuid NOT NULL
>
>    );
>    LOOP
>        INSERT INTO uuid_gen (uuid_gen_col) VALUES (uuid_generate_v1());
>        countmin := countmin + 1;
>        EXIT WHEN countmin > countmax;
>    END LOOP;
>    SELECT COUNT(DISTINCT uuid_gen_col) INTO distinctuuid FROM uuid_gen;
>    IF distinctuuid <> countmax THEN
>        v_message := 'Repeated UUID: FAILS';
>    ELSE
>        v_message := 'NO repeated UUID: OK';
>    END IF;
>    RETURN v_message;
>END;
>$BODY$  LANGUAGE 'plpgsql';