GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-89928: Fix integer conversion of device numbers. by serhiy-storchaka · Pull Request #31794 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Mar 10, 2022 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).

https://bugs.python.org/issue45767

  • Issue: Fix types for dev_t processing in posix module: use uint64_t (unsigned) instead of int64_t (signed) #89928

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
bpo-45767: Fix integer conversion of device numbers.
18ee1e9
Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error needs backport to 3.9 labels Mar 10, 2022
@bedevere-bot bedevere-bot added the awaiting core review label Mar 10, 2022
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Mar 10, 2022
@serhiy-storchaka
Fix compilation on Windows.
c2d082b
@serhiy-storchaka serhiy-storchaka added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 10, 2022
@bedevere-bot

bedevere-bot commented Mar 10, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @serhiy-storchaka for commit c2d082b 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 10, 2022
@ambv ambv removed the needs backport to 3.9 label May 17, 2022
@ambv

ambv commented May 17, 2022

Copy link
Copy Markdown
Contributor

This missed the boat for inclusion in Python 3.9 which accepts security fixes only as of today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.11 only security fixes label May 20, 2022
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
iritkatriel
iritkatriel previously requested changes Nov 27, 2022
View reviewed changes

@iritkatriel iritkatriel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has merge conflicts now.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting core review labels Nov 27, 2022
@bedevere-bot

bedevere-bot commented Nov 27, 2022

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk hugovk removed the needs backport to 3.10 label Apr 7, 2023
@serhiy-storchaka
Merge branch 'main' into long-from-dev_t
53e15e3
@serhiy-storchaka serhiy-storchaka mentioned this pull request Dec 14, 2023
POSIX module incompatible with ZFS on FreeBSD #113078
Closed
serhiy-storchaka added 4 commits December 16, 2023 14:54
@serhiy-storchaka
Merge branch 'main' into long-from-dev_t
2cdb992
@serhiy-storchaka
Support POSIX without NODEV.
90525d0
@serhiy-storchaka
Merge branch 'main' into long-from-dev_t
2e59b79
@serhiy-storchaka
Regen clinic.
17c02dc
@serhiy-storchaka

serhiy-storchaka commented Dec 17, 2023

Copy link
Copy Markdown
Member Author

!buildbot freebsd

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Dec 17, 2023

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @serhiy-storchaka for commit 17c02dc 🤖

The command will test the builders whose names match following regular expression: freebsd

The builders matched are:

  • AMD64 FreeBSD14 PR
  • AMD64 FreeBSD PR
  • AMD64 FreeBSD15 PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Dec 17, 2023

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
Only test NODEV on Linux.
acd102e
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.12 only security fixes label Dec 28, 2023
serhiy-storchaka
serhiy-storchaka commented Jun 3, 2024
View reviewed changes
Comment thread Lib/test/test_posix.py
Comment on lines +728 to +729
if sys.platform == 'linux':
NODEV = -1

@serhiy-storchaka serhiy-storchaka May 24, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to expose posix.NODEV, but this is a different issue.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@kraj kraj Sep 2, 2025

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, musl is another C library implementation on Linux ( like glibc ) which does not provide NODEV, so relying on platform to provide this definition may not be true always.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka serhiy-storchaka added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 3, 2024
@bedevere-bot

bedevere-bot commented Jun 3, 2024

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @serhiy-storchaka for commit 97e71d3 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 3, 2024
@serhiy-storchaka
serhiy-storchaka merged commit 7111d96 into python:main Jun 4, 2024
@miss-islington-app

miss-islington-app Bot commented Jun 4, 2024

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jun 4, 2024
@serhiy-storchaka
serhiy-storchaka deleted the long-from-dev_t branch June 4, 2024 16:36
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 4, 2024
@serhiy-storchaka @miss-islington
pythongh-89928: Fix integer conversion of device numbers (pythonGH-31794
ee7efc3
)

Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
(cherry picked from commit 7111d96)

Co-authored-by: Serhiy Storchaka <[email protected]>
@miss-islington-app

miss-islington-app Bot commented Jun 4, 2024

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f 3.12
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Jun 4, 2024

Copy link
Copy Markdown

GH-120053 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned serhiy-storchaka Jun 4, 2024
@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 4, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jun 4, 2024
@serhiy-storchaka
[3.12] pythongh-89928: Fix integer conversion of device numbers (pyth…
4a81820
…onGH-31794)

Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
(cherry picked from commit 7111d96)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app

bedevere-app Bot commented Jun 4, 2024

Copy link
Copy Markdown

GH-120054 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Jun 4, 2024
@serhiy-storchaka serhiy-storchaka mentioned this pull request Jun 4, 2024
gh-89928: consume dev_t with PyLong_FromUnsignedLongLong #29494
Closed
@vstinner

vstinner commented Jun 4, 2024

Copy link
Copy Markdown
Member

Thanks for the fix @serhiy-storchaka!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added a commit that referenced this pull request Jun 4, 2024
@serhiy-storchaka
[3.12] gh-89928: Fix integer conversion of device numbers (GH-31794) (G…
f98ec75
…H-120054)

Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
(cherry picked from commit 7111d96)
serhiy-storchaka added a commit that referenced this pull request Jun 4, 2024
@miss-islington @serhiy-storchaka
[3.13] gh-89928: Fix integer conversion of device numbers (GH-31794) (G…
2acbdc2
…H-120053)

Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
(cherry picked from commit 7111d96)

Co-authored-by: Serhiy Storchaka <[email protected]>
barneygale pushed a commit to barneygale/cpython that referenced this pull request Jun 5, 2024
@serhiy-storchaka @barneygale
pythongh-89928: Fix integer conversion of device numbers (pythonGH-31794
234a5df
)

Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@serhiy-storchaka @estyxx
pythongh-89928: Fix integer conversion of device numbers (pythonGH-31794
7dd6d8d
)

Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
@kraj kraj mentioned this pull request Sep 9, 2025
test_posix.test_makedev fails on Musl systems #138707
Closed
rlbdv added a commit to rlbdv-ci/bup that referenced this pull request May 25, 2026
@rlbdv
Be more careful with the stat types (dev_t, etc.)
92b77d6
Tests on freebsd with zfs failed with OverflowErrors because zfs was
creating a device (dev_t) with the high bit set (which is is known to
to), and it turns out that python hasn't handled that consistently.
Recent python versions handle it as unsigned, ignoring the platform's
definition (e.g. on macos it's signed), in nearly all cases.  Though
it looks like os.makedev() is still broken.

Python improved the "high bit set" dev_t handling here (switching, as
mentioned, by trying to shift to treat them as unsigned):

[1] 7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f
    gh-89928: Fix integer conversion of device numbers (GH-31794)
    python/cpython#31794

And those changes have been backported to an increasing number of
python minor releases.

I believe we were exposed to these errors when I removed our custom
stat function:

  commit ae032d6
  Drop our custom stat functions in favor of python's

To date, bup has also required dev_t (and some other stat fields) to
be signed and no more than eight bytes via use of Q in the INDEX_SIG
pack format for index entries.  Whether or not python also attempts to
treat all of these consistently as unsigned has not been investigated.

To address the dev_t issue, and to make sure we handle all the other
stat fields consistently over time and across python versions, bring
back and enhance our custom stat functions, provide compatible
versions of major() and minor(), and wrap os.mknod() to make sure it
only sees the unsigned device values it expects (we don't just wrap
mknod too because it's a bit more complex, and it doesn't appear to
have changed behavior over the perids we investigated).

Have all of our stat operations work with the actual platform
ranges (i.e. preserve unsigned/signed values), and make sure that the
index doesn't lose the stat field sign information by providing the
platform specific entry type signature to the index from _helpers.

So that we don't mishandle the index (even across hosts, say via
moving a bup repo from one machine to another), add the entry
signature to the index's header and require reindexing if the current
platform's entry signature doesn't match the one in the index.
Continue to support the previous index format (trivially) so that if
the entry signature hasn't actually changed, you don't have to reindex
just for the new format.

Rename INDEX_SIG to ENTRY_SIG since that's what it is, and rename
INDEX_HDR to INDEX_SIG since that's what *it* is.

(Given these changes, we could also make the index signature even more
 dynamic, i.e. shrink all the entries to the actual platform sizes,
 e.g. on linux, uid and gid could be 4 bytes.)

Thanks to Johannes Berg for a good bit of help figuring all this out.

Signed-off-by: Rob Browning <[email protected]>
Tested-by: Rob Browning <[email protected]>
rlbdv added a commit to rlbdv-ci/bup that referenced this pull request May 25, 2026
@rlbdv
Be more careful with the stat types (dev_t, etc.)
f4f0a27
Tests on freebsd with zfs failed with OverflowErrors because zfs was
creating a device (dev_t) with the high bit set (which is is known to
to), and it turns out that python hasn't handled that consistently.
Recent python versions handle it as unsigned, ignoring the platform's
definition in nearly all cases (e.g. on macos it's signed).  Though it
looks like os.makedev() is still broken.

Python improved the "high bit set" dev_t handling in this
commit (switching, as mentioned, to try to treat them as unsigned):

[1] 7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f
    gh-89928: Fix integer conversion of device numbers (GH-31794)
    python/cpython#31794

And those changes have been backported to an increasing number of
python minor releases.  (Whether or not python attempts to treat stat
fields other than dev_t as unsigned consistently has not been
investigated.)

I believe we were exposed to these errors when I removed our custom
stat function in main:

  commit ae032d6
  Drop our custom stat functions in favor of python's

To date, bup has required dev_t (and some other stat fields) to be
unsigned too, and no more than eight bytes, via use of Q in the
INDEX_SIG pack format for index entries.

To address the dev_t issue, and to make sure we handle all the other
stat fields consistently over time and across python versions, bring
back and enhance our custom stat functions, provide compatible
versions of major() and minor(), and wrap python's os.mknod() to make
sure it only sees the unsigned device values it expects (we don't wrap
mknod too because it's a bit more complex, and it doesn't appear to
have changed behavior over the periods we investigated).

Have all of our stat operations work with the actual platform
ranges (i.e. preserve unsigned/signed values), and make sure that the
index doesn't lose the stat field sign information by providing the
platform specific entry type signature to the index from _helpers.

Finally, so that we don't mishandle the index (even across hosts, say
via moving a bup repo from one machine to another), add the entry
signature to the index's header and require reindexing if the current
platform's signature doesn't match the one in the index.  Continue to
support the previous index format (trivially) so that if the entry
signature hasn't actually changed, you don't have to reindex just for
the new format.

Rename INDEX_SIG to ENTRY_SIG since that's what it is, and rename
INDEX_HDR to INDEX_SIG since that's what *it* is.

Thanks to Johannes Berg for a good bit of help figuring all this out.

Signed-off-by: Rob Browning <[email protected]>
Tested-by: Rob Browning <[email protected]>
rlbdv added a commit to rlbdv-ci/bup that referenced this pull request May 25, 2026
@rlbdv
Be more careful with the stat types (dev_t, etc.)
0e67cd5
Tests on freebsd with zfs failed with OverflowErrors because zfs was
creating a device (dev_t) with the high bit set (which is is known to
to), and it turns out that python hasn't handled that consistently.
Recent python versions handle it as unsigned, ignoring the platform's
definition in nearly all cases (e.g. on macos it's signed).  Though it
looks like os.makedev() is still broken.

Python improved the "high bit set" dev_t handling in this
commit (switching, as mentioned, to try to treat them as unsigned):

[1] 7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f
    gh-89928: Fix integer conversion of device numbers (GH-31794)
    python/cpython#31794

And those changes have been backported to an increasing number of
python minor releases.  (Whether or not python attempts to treat stat
fields other than dev_t as unsigned consistently has not been
investigated.)

I believe we were exposed to these errors when I removed our custom
stat function in main:

  commit ae032d6
  Drop our custom stat functions in favor of python's

To date, bup has required dev_t (and some other stat fields) to be
unsigned too, and no more than eight bytes, via use of Q in the
INDEX_SIG pack format for index entries.

To address the dev_t issue, and to make sure we handle all the other
stat fields consistently over time and across python versions, bring
back and enhance our custom stat functions, provide compatible
versions of major() and minor(), and wrap python's os.mknod() to make
sure it only sees the unsigned device values it expects (we don't wrap
mknod too because it's a bit more complex, and it doesn't appear to
have changed behavior over the periods we investigated).

Have all of our stat operations work with the actual platform
ranges (i.e. preserve unsigned/signed values), and make sure that the
index doesn't lose the stat field sign information by providing the
platform specific entry type signature to the index from _helpers.

Finally, so that we don't mishandle the index (even across hosts, say
via moving a bup repo from one machine to another), add the entry
signature to the index's header and require reindexing if the current
platform's signature doesn't match the one in the index.  Continue to
support the previous index format (trivially) so that if the entry
signature hasn't actually changed, you don't have to reindex just for
the new format.

Rename INDEX_SIG to ENTRY_SIG since that's what it is, and rename
INDEX_HDR to INDEX_SIG since that's what *it* is.

Thanks to Johannes Berg for a good bit of help figuring all this out.

Signed-off-by: Rob Browning <[email protected]>
Tested-by: Rob Browning <[email protected]>
rlbdv added a commit to rlbdv-ci/bup that referenced this pull request May 25, 2026
@rlbdv
Be more careful with the stat types (dev_t, etc.)
7555e3d
Tests on freebsd with zfs failed with OverflowErrors because zfs was
creating a device (dev_t) with the high bit set (which is is known to
to), and it turns out that python hasn't handled that consistently.
Recent python versions handle it as unsigned, ignoring the platform's
definition in nearly all cases (e.g. on macos it's signed).  Though it
looks like os.makedev() is still broken.

Python improved the "high bit set" dev_t handling in this
commit (switching, as mentioned, to try to treat them as unsigned):

[1] 7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f
    gh-89928: Fix integer conversion of device numbers (GH-31794)
    python/cpython#31794

And those changes have been backported to an increasing number of
python minor releases.  (Whether or not python attempts to treat stat
fields other than dev_t as unsigned consistently has not been
investigated.)

I believe we were exposed to these errors when I removed our custom
stat function in main:

  commit ae032d6
  Drop our custom stat functions in favor of python's

To date, bup has required dev_t (and some other stat fields) to be
unsigned too, and no more than eight bytes, via use of Q in the
INDEX_SIG pack format for index entries.

To address the dev_t issue, and to make sure we handle all the other
stat fields consistently over time and across python versions, bring
back and enhance our custom stat functions, provide compatible
versions of major() and minor(), and wrap python's os.mknod() to make
sure it only sees the unsigned device values it expects (we don't wrap
mknod too because it's a bit more complex, and it doesn't appear to
have changed behavior over the periods we investigated).

Have all of our stat operations work with the actual platform
ranges (i.e. preserve unsigned/signed values), and make sure that the
index doesn't lose the stat field sign information by providing the
platform specific entry type signature to the index from _helpers.

Finally, so that we don't mishandle the index (even across hosts, say
via moving a bup repo from one machine to another), add the entry
signature to the index's header and require reindexing if the current
platform's signature doesn't match the one in the index.  Continue to
support the previous index format (trivially) so that if the entry
signature hasn't actually changed, you don't have to reindex just for
the new format.

Rename INDEX_SIG to ENTRY_SIG since that's what it is, and rename
INDEX_HDR to INDEX_SIG since that's what *it* is.

Thanks to Johannes Berg for a good bit of help figuring all this out.

Signed-off-by: Rob Browning <[email protected]>
Tested-by: Rob Browning <[email protected]>
rlbdv added a commit to rlbdv-ci/bup that referenced this pull request Jun 15, 2026
@rlbdv
Be more careful with the stat types (dev_t, etc.)
59d1efe
Tests on freebsd with zfs failed with OverflowErrors because zfs was
creating a device (dev_t) with the high bit set (which it is known
to), and it turns out that python hasn't handled that consistently.
Recent python versions handle it as unsigned, ignoring the platform's
definition in nearly all cases (e.g. on macos it's signed).  Though it
looks like os.makedev() is still broken.

Python improved the "high bit set" dev_t handling in this
commit (switching, as mentioned, to try to treat them as unsigned):

  7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f
  gh-89928: Fix integer conversion of device numbers (GH-31794)
  python/cpython#31794

And those changes have been backported to an increasing number of
python minor releases.  (Whether or not python attempts to treat stat
fields other than dev_t as unsigned consistently has not been
investigated.)

I believe we were exposed to these errors when I removed our custom
stat function in main:

  ae032d6
  Drop our custom stat functions in favor of python's

To date, bup has also required dev_t (and some other stat fields) to
be unsigned and no more than eight bytes, via use of Q in the
INDEX_SIG pack format for index entries.

To address the dev_t issue, and to make sure we handle all the other
stat fields consistently over time and across python versions, bring
back and enhance our custom stat functions, and wrap python's
os.mknod() to make sure it only sees the unsigned device values it
expects (for now we don't add our own mknod because it's a bit more
complex, and python's doesn't appear to have changed behavior over the
periods we investigated).

Have all of our stat operations work with the actual platform
ranges (i.e. preserve unsigned/signed values), and make sure that the
index doesn't lose the stat field sign information by providing the
platform size and sign via _helpers.c_type_signed_size.

Finally, so that we don't mishandle the index (even across hosts, say
via moving a bup repo from one machine to another), add the entry
signature to the index's header and require reindexing if the current
platform's signature doesn't match the one in the index.  Continue to
support the previous index format (trivially) so that if the entry
signature hasn't actually changed, you don't have to reindex just for
the new format.

Rename INDEX_SIG to ENTRY_SIG since that's what it is, and rename
INDEX_HDR to INDEX_SIG since that's what *it* is.

Add bup_int_from_py to pyutil and move the (u)int functions above
bup_ulong_from_py.

Thanks to Johannes Berg for a good bit of help figuring all this out.

Signed-off-by: Rob Browning <[email protected]>
Tested-by: Rob Browning <[email protected]>
rlbdv added a commit to rlbdv-ci/bup that referenced this pull request Jun 16, 2026
@rlbdv
Be more careful with the stat types (dev_t, etc.)
e5cb526
Tests on freebsd with zfs failed with OverflowErrors because zfs was
creating a device (dev_t) with the high bit set (which it is known
to), and it turns out that python hasn't handled that consistently.
Recent python versions handle it as unsigned, ignoring the platform's
definition in nearly all cases (e.g. on macos it's signed).  Though it
looks like os.makedev() is still broken.

Python improved the "high bit set" dev_t handling in this
commit (switching, as mentioned, to try to treat them as unsigned):

  7111d9605f9db7aa0b095bb8ece7ccc0b8115c3f
  gh-89928: Fix integer conversion of device numbers (GH-31794)
  python/cpython#31794

And those changes have been backported to an increasing number of
python minor releases.  (Whether or not python attempts to treat stat
fields other than dev_t as unsigned consistently has not been
investigated.)

I believe we were exposed to these errors when I removed our custom
stat function in main:

  ae032d6
  Drop our custom stat functions in favor of python's

To date, bup has also required dev_t (and some other stat fields) to
be unsigned and no more than eight bytes, via use of Q in the
INDEX_SIG pack format for index entries.

To address the dev_t issue, and to make sure we handle all the other
stat fields consistently over time and across python versions, bring
back and enhance our custom stat functions, and wrap python's
os.mknod() to make sure it only sees the unsigned device values it
expects (for now we don't add our own mknod because it's a bit more
complex, and python's doesn't appear to have changed behavior over the
periods we investigated).

Have all of our stat operations work with the actual platform
ranges (i.e. preserve unsigned/signed values), and make sure that the
index doesn't lose the stat field sign information by providing the
platform size and sign via _helpers.c_type_signed_size.

Finally, so that we don't mishandle the index (even across hosts, say
via moving a bup repo from one machine to another), add the entry
signature to the index's header and require reindexing if the current
platform's signature doesn't match the one in the index.  Continue to
support the previous index format (trivially) so that if the entry
signature hasn't actually changed, you don't have to reindex just for
the new format.

Rename INDEX_SIG to ENTRY_SIG since that's what it is, and rename
INDEX_HDR to INDEX_SIG since that's what *it* is.

Add bup_int_from_py to pyutil and move the (u)int functions above
bup_ulong_from_py.

Thanks to Johannes Berg for a good bit of help figuring all this out.

Signed-off-by: Rob Browning <[email protected]>
Tested-by: Rob Browning <[email protected]>
@serhiy-storchaka serhiy-storchaka removed their assignment Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@iritkatriel iritkatriel iritkatriel left review comments
+1 more reviewer
@kraj kraj kraj left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@serhiy-storchaka @bedevere-bot @ambv @vstinner @kraj @iritkatriel @hugovk @the-knights-who-say-ni @ezio-melotti
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.