traperto / magic-bytes-validator Goto Github PK
View Code? Open in Web Editor NEWFile validator that checks by magic bytes and MIME types
License: MIT License
File validator that checks by magic bytes and MIME types
License: MIT License
This is not a real "issue" but rather an idea that I had. Currently, we cannot handle special quirks (like offsets, variable bytes inside a sequence or final byte sequences) really well. This is based on our architecture, which handles every FileType the same. To mitigate those problems, we could refactor our matching logic:
An IFileType
has a bool Matches(byte[] bytes)
method, which returns whether a given (complete) file stream matches a file type. An abstract AbstractStartSequencesFileType : IFileType
could implement the Matches
method to validate its magic byte sequences (given by its inheritors) just like we match the file types today.
File types with special magic bytes logic could be implemented clean and encapsulated in the file type only. A drawback would be, that we need to load the complete file stream before matching. But this is necessary to be completely sure that the file type matches.
This would obviously be a major breaking change. Therefore we would be forced to make it a v2. Depending on how many other people depend on this package, we should support the v1 alongside v2, at least for some time.
What do you think about this?
e.g. PNG
Thanks for this library, I've found it very useful in a project I'm working on. However I've found that when evaluating magic bytes with the StreamFileTypeProvider
, the offset is never considered, meaning that the mp4
format will never be discovered (or others that might be supported in the future that have offset bytes)
I'm sending a pull request with this fix and an optimization when ordering the sizes to find the maximum bytes size for the buffer,
Thanks for your hard work!
You are missing a LICENSE file in your repository. Please add it using the guide in the following link. https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/adding-a-license-to-a-repository
It is not enough to simply mention that the license is an MIT license, otherwise everyone using this repo is legally liable and this could have major monetary consequences for your users.
Sometimes you don't have a extension nor a mimetype and the only way is to detect is by inspecting the data and look for magic bytes.
Since the library also knows the magic bytes it would be great if it also offers a detection mechanism.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.