Skip to content

Implement libmagic parameters (configuration values)#453

Draft
robo9k wants to merge 1 commit into
mainfrom
param
Draft

Implement libmagic parameters (configuration values)#453
robo9k wants to merge 1 commit into
mainfrom
param

Conversation

@robo9k
Copy link
Copy Markdown
Owner

@robo9k robo9k commented Apr 3, 2026

References
#433 (comment)

Description
Implement libmagic "parameters" - configuration values

@robo9k robo9k changed the title Param Implement libmagic parameters (configuration values) Apr 3, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 48.66667% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.19%. Comparing base (a755b9f) to head (f96dc6b).

Files with missing lines Patch % Lines
src/lib.rs 46.72% 34 Missing and 23 partials ⚠️
src/ffi.rs 53.48% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #453      +/-   ##
==========================================
+ Coverage   46.75%   47.19%   +0.43%     
==========================================
  Files           2        2              
  Lines         509      659     +150     
  Branches      509      659     +150     
==========================================
+ Hits          238      311      +73     
- Misses        270      324      +54     
- Partials        1       24      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@robo9k
Copy link
Copy Markdown
Owner Author

robo9k commented Apr 3, 2026

Okay, calling magic_setparam(MAGIC_PARAM_ELF_SHSIZE_MAX) on libmagic < v5.45 fails, which causes the MSRV verification with --all-features to fail indirectly
This is a deficiency in the cargo msrv CI

However, it fails with

SetParamError { param: 8, source: ApiViolation(MissingError("`magic_setparam()` did not set last error")) }

This seems to be due to a misunderstanding of how libmagic returns errors in that case, the logic has been taken from #433
Annoyingly this is not documented by libmagic either!

Looking at its current implementation, magic_setparam behaves more like e.g. magic_open in that it only sets errno (to EINVAL). Same with magic_getparam.

So our implementation needs to be fixed to return the correct but undocumented error.

@robo9k
Copy link
Copy Markdown
Owner Author

robo9k commented Apr 3, 2026

The MSRV failure is still weird
There's other CI workflows that are also roughly running cargo test --locked --all-targets --all-features but they do succeed! And they use the same libmagic version from same ubuntu packages!
cargo msrv find also claims that while 1.64 is incompatible, 1.65 would work - what?!

The error with 1.64 seems to be

error: unnecessary `unsafe` block

I don't see any changes that would allow this with 1.65 https://releases.rs/docs/1.65.0/

@robo9k
Copy link
Copy Markdown
Owner Author

robo9k commented Apr 3, 2026

I don't understand why unsafe-in-unsafe caused an error when testing MSRV against 1.64 but not 1.65, but it's possibly best to postpone this to an edition update (and likely MSRV bump as well) which would make it fully supported

@robo9k robo9k marked this pull request as draft April 3, 2026 20:14
@robo9k
Copy link
Copy Markdown
Owner Author

robo9k commented Apr 3, 2026

TODO: This currently panic!s on unexpected libmagic return values for set_param and get_param, so might run into the same issues as #372
Even if the logic is kept that way, the rustdoc currently isn't accurate about error vs panic

@robo9k
Copy link
Copy Markdown
Owner Author

robo9k commented Apr 4, 2026

Note that in magic.h params do not have a name other than their MAGIC_PARAM_*_MAX define

but in the fle CLI they do have names for the --parameter name=value option, see setparam() in src/file.c
https://github.com/file/file/blob/adfc2a0c50085e7a95f8814f817624b3c37034d2/src/file.c#L143-L171

The struct pm also uses size_t for all params.

Signed-off-by: robot9001 <robo9k@symlink.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant