Skip to content

value out of range [RangeDefect] in getFileInfo() for a specific file (file handle overflow?) #23442

@mkpoli

Description

@mkpoli

Description

I meet this error when using monit library where it will fail to watch. After a little inspection I found out that the error does not come from the package it self. It is from the internals getFileInfo() however I could not find where the problem is. So there is a file called test_converter.nim which is a extremely ordinary test file with nothing special, but for god knows why it just cannot be getFileInfo'd.

import os echo os.getFileInfo("C:/Users/mk/Desktop/Suno AI/Ainu/converter-nim/tests/test_converter.nim")

I tried to:

  • make a copy manually -> Working
  • recreate the file manually -> Working
  • reconstruct the file from compressed file -> Working
  • change other file to the same path and name -> Working
  • move the corrupted test_converter.nim around -> Error

So this is only the case for the corrupted file, and there must be something different of that file. The data itself does not matter, so there must be some thing weird in file info.

import os echo "Copied file: test_converter2.nim" echo os.getFileInfo("C:/Users/mk/Desktop/Suno AI/Ainu/converter-nim/tests/test_converter2.nim") echo "" echo "Recreated file: test_converter3.nim" echo os.getFileInfo("C:/Users/mk/Desktop/Suno AI/Ainu/converter-nim/tests/test_converter3.nim") echo "" echo "Reconstructed file: test_converter4.nim" echo os.getFileInfo("C:/Users/mk/Desktop/Suno AI/Ainu/converter-nim/tests/test_converter4.nim") echo "" echo "Corrupted file: test_converter.nim" echo os.getFileInfo("C:/Users/mk/Desktop/Suno AI/Ainu/converter-nim/tests/test_converter.nim")

yields:

Copied file: test_converter2.nim (id: (device: -2044898135, file: 8725724283740323), kind: pcFile, size: 304, permissions: {fpUserExec, fpUserWrite, fpUserRead, fpGroupExec, fpGroupWrite, fpGroupRead, fpOthersExec, fpOthersWrite, fpOthersRead}, linkCount: 1, lastAccessTime: (seconds: 1711481959, nanosecond: 481313200), lastWriteTime: (seconds: 1711480595, nanosecond: 981107800), creationTime: (seconds: 1711474744, nanosecond: 759355000), blockSize: 8192, isSpecial: false) Recreated file: test_converter3.nim (id: (device: -2044898135, file: 8444249306668620), kind: pcFile, size: 304, permissions: {fpUserExec, fpUserWrite, fpUserRead, fpGroupExec, fpGroupWrite, fpGroupRead, fpOthersExec, fpOthersWrite, fpOthersRead}, linkCount: 1, lastAccessTime: (seconds: 1711481961, nanosecond: 657333700), lastWriteTime: (seconds: 1711477758, nanosecond: 585807400), creationTime: (seconds: 1711480930, nanosecond: 475884100), blockSize: 8192, isSpecial: false) Reconstructed file: test_converter4.nim (id: (device: -2044898135, file: 132011764078828729), kind: pcFile, size: 304, permissions: {fpUserExec, fpUserWrite, fpUserRead, fpGroupExec, fpGroupWrite, fpGroupRead, fpOthersExec, fpOthersWrite, fpOthersRead}, linkCount: 1, lastAccessTime: (seconds: 1711481962, nanosecond: 164339700), lastWriteTime: (seconds: 1711477758, nanosecond: 585807400), creationTime: (seconds: 1711481858, nanosecond: 856398400), blockSize: 8192, isSpecial: false) Corrupted file: test_converter.nim C:\Users\mk\Desktop\Suno AI\Ainu\converter-nim\wtf.nim(15) wtf C:\Users\mk\.choosenim\toolchains\nim-2.0.2\lib\pure\os.nim(755) getFileInfo C:\Users\mk\.choosenim\toolchains\nim-2.0.2\lib\system\fatal.nim(53) sysFatal Error: unhandled exception: value out of range [RangeDefect] 

I tried also usinng Python to get the file info, it works fine:

from pathlib import Path file = Path(".\\tests\\test_converter2.nim") print(file) print(file.stat()) print() file = Path(".\\tests\\test_converter3.nim") print(file) print(file.stat()) print() file = Path(".\\tests\\test_converter4.nim") print(file) print(file.stat()) print() file = Path(".\\test_converter.nim") print(file) print(file.stat())

yields:

tests\test_converter2.nim os.stat_result(st_mode=33206, st_ino=8725724283740323, st_dev=3928860244374803625, st_nlink=1, st_uid=0, st_gid=0, st_size=304, st_atime=1711481959, st_mtime=1711480595, st_ctime=1711474744) tests\test_converter3.nim os.stat_result(st_mode=33206, st_ino=8444249306668620, st_dev=3928860244374803625, st_nlink=1, st_uid=0, st_gid=0, st_size=304, st_atime=1711481961, st_mtime=1711477758, st_ctime=1711480930) tests\test_converter4.nim os.stat_result(st_mode=33206, st_ino=132011764078828729, st_dev=3928860244374803625, st_nlink=1, st_uid=0, st_gid=0, st_size=304, st_atime=1711481962, st_mtime=1711477758, st_ctime=1711481858) tests\test_converter.nim os.stat_result(st_mode=33206, st_ino=10113114438237264467, st_dev=3928860244374803625, st_nlink=1, st_uid=0, st_gid=0, st_size=304, st_atime=1711481971, st_mtime=1711477758, st_ctime=1711474744) 

Comparing the result, I doubt if the problems comes with the file handle st_ino, or id.file is too long? It is close to 2^64 but not really.

Nim Version

Nim Compiler Version 2.0.2 [Windows: amd64]
Compiled at 2023-12-15
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

Current Output

51088 lines; 1.384s; 71.055MiB peakmem; proj: C:\Users\mk\Desktop\Suno AI\Ainu\converter-nim\wtf.nim; out: C:\Users\mk\Desktop\Suno AI\Ainu\converter-nim\wtf.exe [SuccessX] C:\Users\mk\Desktop\Suno AI\Ainu\converter-nim\wtf.nim(3) wtf C:\Users\mk\.choosenim\toolchains\nim-2.0.2\lib\pure\os.nim(755) getFileInfo C:\Users\mk\.choosenim\toolchains\nim-2.0.2\lib\system\fatal.nim(53) sysFatal Error: unhandled exception: value out of range [RangeDefect] 

Expected Output

(id: (device: -2044898135, file: 8444249306668620), kind: pcFile, size: 304, permissions: {fpUserExec, fpUserWrite, fpUserRead, fpGroupExec, fpGroupWrite, fpGroupRead, fpOthersExec, fpOthersWrite, fpOthersRead}, linkCount: 1, lastAccessTime: (seconds: 1711480930, nanosecond: 476384400), lastWriteTime: (seconds: 1711477758, nanosecond: 585807400), creationTime: (seconds: 1711480930, nanosecond: 475884100), blockSize: 8192, isSpecial: false) 

Possible Solution

Inspect the code in getFileInfo()?

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions