Skip to content

Alias.for_file creates an Alias object which cannot be written due to containing out of range CNIDs #22

@hakanai

Description

@hakanai

Currently, if I use Alias.for_file to produce an alias pointing to a file, it produces an Alias object, but then calling to_bytes() on that object fails.

On closer inspection, the generated cnid_path contains a couple of IDs which are out of range for an unsigned 32-bit int.

% python3       
Python 3.9.6 (default, Sep 26 2022, 11:37:49) 
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from mac_alias import Alias
>>> a = Alias.for_file("/Applications")
>>> a.target.cnid_path
[2, 1152921500311879701, 1152921500312727487]
>>> a.to_bytes()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/Library/Python/3.9/lib/python/site-packages/mac_alias/alias.py", line 754, in to_bytes
    self._to_fd(b)
  File "~/Library/Python/3.9/lib/python/site-packages/mac_alias/alias.py", line 636, in _to_fd
    cnid_path = struct.pack(
struct.error: 'I' format requires 0 <= number <= 4294967295
>>> 

I don't know what the CNID path is supposed to contain, but I'm guessing that 2 is the ID for /Applications (it's about as small as I'd expect /Applications to have) and the other two are presumably whatever macOS considers to be the parent.

If I look at carbon_path, that contains "Data:..:\x00..:\x00..:\x00Applications".

This is with current main branch, running on macOS Monterey.

We use this as part of building DMGs in our build as well, and those still seem to be working, so it could be that our build machines are still running an earlier version of macOS which is not affected. (Or, it could be we're getting an earlier version of mac_alias which doesn't have the issue, but that seems less likely.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions