Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError when converting os.getxattr result to float in get_ctime_linux #1244

Open
JingofXin opened this issue Nov 28, 2024 · 4 comments
Open

Comments

@JingofXin
Copy link

Actual Behavior: A ValueError is raised when attempting to convert the result of os.getxattr to a float. The output from os.getxattr appears to be corrupted or in an incorrect format.

Error Traceback:

Traceback (most recent call last):
  File "loguru/_ctime_functions.py", line 36, in get_ctime_linux
    return float(os.getxattr(filepath, b"user.loguru_crtime"))
ValueError: could not convert string to float: b'1721180095.264594\xdc:\xee|Q\x7f?WA\xf8\x8bdC\xe9V\xbdW\x19q\x80'

image

@Delgan
Copy link
Owner

Delgan commented Nov 28, 2024

Hi @JingofXin.

What is your OS version please?

@JingofXin
Copy link
Author

Hi @JingofXin.

What is your OS version please?

Ubuntu 22.04.3 LTS

@JingofXin
Copy link
Author

I’ve modified the code to handle the exception, which now bypasses the issue as follows:

def get_ctime_linux(filepath):
    try:
        return float(os.getxattr(filepath, b"user.loguru_crtime"))
    except Exception:
        return os.stat(filepath).st_mtime

@Delgan
Copy link
Owner

Delgan commented Nov 28, 2024

It's a real mystery how you end up with such weird value after the timestamp.

>>> print("\xdc:\xee|Q\x7f?WA\xf8\x8bdC\xe9V\xbdW\x19q\x80")
Ü:î|Q?WAødCéV½Wq

I don't think this is a bug in Loguru. Could it be that a program in your system is modifying the extended Linux attributes?

Do you have more context about how the problem occurs? Does it happen at the beginning or during execution? Is it systematic? Have you tried another log file?

What about the output of the following script:

import os

with open("random_file.txt", "w") as f:
    f.write("Hello, World!")

os.setxattr("random_file.txt", b"user.loguru_crtime", "1234567890.123456".encode("ascii"))

res = os.getxattr("random_file.txt", b"user.loguru_crtime")

print(res)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants