[pve-devel] [PATCH qemu-server 01/13] blockdev: cmdline: add blockdev syntax support

Fiona Ebner f.ebner at proxmox.com
Tue Jun 10 16:03:47 CEST 2025


The way the node name encoding is implemented is problematic as we
operate outside of integer ranges:

[I] febner at dev8 ~/repos/pve/qemu-server (qemu-blockdev-options)> cat asdf.pm
use strict;
use warnings;

use Digest::SHA;

sub encode_base62 {
    my ($input) = @_;

    my @chars = ('0'..'9', 'A'..'Z', 'a'..'z');
    my $base = 62;
    my $value = 0;

    my $result = '';
    for my $byte (unpack('C*', $input)) {
	$value = $value * 256 + $byte;
	print "$value\n";
    }
}

encode_base62(Digest::SHA::sha1("foo"));
[I] febner at dev8 ~/repos/pve/qemu-server (qemu-blockdev-options)> perl
asdf.pm
11
3054
782023
200198069
51250705898
13120180709951
3358766261747471
859844163007352795
2.20120105729882e+20
5.63507470668499e+22
1.44257912491136e+25
3.69300255977307e+27
9.45408655301907e+29
2.42024615757288e+32
6.19583016338658e+34
1.58613252182696e+37
4.06049925587703e+39
1.03948780950452e+42
2.66108879233157e+44
6.81238730836881e+46

Also, while the use case here shouldn't be cryptographically sensitive,
you never know, so I'll just use a different hash function than sha1.
I'll cut off the result from that hash to 30 hex digits. Then we still
have one letter for the prefix of the node name.

As for collision probability, that will be 120 bits and should be more
than enough, even 2^50 nodes have a very small probability to collide
with that:

>>> math.log2(16**30)
120.0
>>> d=2**120
>>> n=2**50
>>> 1 - math.exp(-(n*n)/(2*d))
4.768370445162873e-07





More information about the pve-devel mailing list