From 293c953cd8e983b88e3a09cbe884c4a13d590df8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 1 Mar 2026 08:00:05 +0000 Subject: [PATCH 1/4] chore: release v0.2.0 --- CHANGELOG.md | 14 ++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2607efb1..e1209aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. +## [0.2.0] - 2026-03-01 + +### Features + +- **parser**: Implement comparison operators ([#104](https://github.com/EvilBit-Labs/libmagic-rs/pull/104)) + +### Miscellaneous Tasks + +- **Mergify**: Add outdated PR protection ([#75](https://github.com/EvilBit-Labs/libmagic-rs/pull/75)) +- Add Mergify merge queue and simplify CI ([#78](https://github.com/EvilBit-Labs/libmagic-rs/pull/78)) +- Mergify merge queue, dependabot integration, and CI simplification ([#79](https://github.com/EvilBit-Labs/libmagic-rs/pull/79)) +- **release**: Add regex for version bumping based on commit types + + ## [0.1.1] - 2026-02-15 ### Miscellaneous Tasks diff --git a/Cargo.lock b/Cargo.lock index 77620881..87531825 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -494,7 +494,7 @@ checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libmagic-rs" -version = "0.1.1" +version = "0.2.0" dependencies = [ "byteorder", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 2cca3267..6e7c093d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libmagic-rs" -version = "0.1.1" +version = "0.2.0" edition = "2024" authors = [ "UncleSp1d3r ", From c339b9e9539fb95c7d3719ade0b0e8cefd7ed9de Mon Sep 17 00:00:00 2001 From: "dosubot[bot]" <131922026+dosubot[bot]@users.noreply.github.com> Date: Sun, 1 Mar 2026 17:21:57 +0000 Subject: [PATCH 2/4] docs: Dosu updates for PR #111 --- docs/GETTING_STARTED.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/GETTING_STARTED.md b/docs/GETTING_STARTED.md index e19dfb10..ce970d9d 100644 --- a/docs/GETTING_STARTED.md +++ b/docs/GETTING_STARTED.md @@ -21,9 +21,11 @@ Add libmagic-rs to your `Cargo.toml`: ```toml [dependencies] -libmagic-rs = "0.1" +libmagic-rs = "0.2" ``` +**Note:** Version 0.2.0 introduces breaking changes. If upgrading from 0.1.x, note that `TypeKind::Byte` changed from a unit variant to a tuple variant, and the `Operator` enum gained new variants (`LessThan`, `GreaterThan`, `LessEqual`, `GreaterEqual`) for comparison operations. Exhaustive pattern matching on these enums requires updates. + ### Build from Source ```bash @@ -61,7 +63,7 @@ Edit `Cargo.toml`: ```toml [dependencies] -libmagic-rs = "0.1" +libmagic-rs = "0.2" ``` #### Step 3: Write Code From 8522dada5ef789038c3647b40fb01392620add58 Mon Sep 17 00:00:00 2001 From: "dosubot[bot]" <131922026+dosubot[bot]@users.noreply.github.com> Date: Sun, 1 Mar 2026 17:27:54 +0000 Subject: [PATCH 3/4] docs: Dosu updates for PR #111 --- docs/src/release-process.md | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/docs/src/release-process.md b/docs/src/release-process.md index 06844944..abb65040 100644 --- a/docs/src/release-process.md +++ b/docs/src/release-process.md @@ -105,24 +105,21 @@ version = "0.2.0" # Update version ```markdown # Changelog -## [0.2.0] - 2024-03-15 +## [0.2.0] - 2026-03-01 -### Added -- Magic file parser implementation -- Basic rule evaluation engine -- Memory-mapped file I/O support +### Features +- **parser**: Implement comparison operators -### Changed -- Improved AST structure for better performance -- Enhanced error messages with more context - -### Fixed -- Buffer overflow protection in string reading -- Proper handling of indirect offsets +### Miscellaneous Tasks +- **Mergify**: Add outdated PR protection +- Add Mergify merge queue and simplify CI +- Mergify merge queue, dependabot integration, and CI simplification +- **release**: Add regex for version bumping based on commit types ### Breaking Changes -- `EvaluationConfig` structure modified -- `MagicRule::new()` signature changed +- `TypeKind::Byte` variant changed from unit variant to a different kind +- `Operator` enum: added `LessThan`, `GreaterThan`, `LessEqual`, `GreaterEqual` variants (exhaustive enum) +- `read_byte` function signature changed (parameter count modified) ``` ### Release Creation From c3ebf421557011b9fff0b2836fb38087c19c7b63 Mon Sep 17 00:00:00 2001 From: "dosubot[bot]" <131922026+dosubot[bot]@users.noreply.github.com> Date: Sun, 1 Mar 2026 20:17:19 +0000 Subject: [PATCH 4/4] docs: Dosu updates for PR #111 --- docs/API_REFERENCE.md | 14 ++++-- docs/src/api-reference.md | 16 ++++-- docs/src/ast-structures.md | 4 ++ docs/src/evaluator.md | 60 ++++++++++++++++++++-- docs/src/migration.md | 100 +++++++++++++++++++++++++++++++++++++ docs/src/parser.md | 4 +- 6 files changed, 182 insertions(+), 16 deletions(-) diff --git a/docs/API_REFERENCE.md b/docs/API_REFERENCE.md index a2ffe62e..3af1ca3f 100644 --- a/docs/API_REFERENCE.md +++ b/docs/API_REFERENCE.md @@ -298,11 +298,13 @@ use libmagic_rs::TypeKind; | Variant | Description | |---------|-------------| -| `Byte { signed }` | Single byte with explicit signedness | +| `Byte { signed }` | Single byte with explicit signedness (changed in v0.2.0) | | `Short { endian, signed }` | 16-bit integer | | `Long { endian, signed }` | 32-bit integer | | `String { max_length }` | String data | +**Version Note:** In v0.2.0, the `Byte` variant changed from a unit variant to a struct variant with a `signed` field. + #### Operator Comparison operators. @@ -315,13 +317,15 @@ use libmagic_rs::Operator; |---------|-------------| | `Equal` | Equality comparison (`=` or `==`) | | `NotEqual` | Inequality comparison (`!=` or `<>`) | -| `LessThan` | Less than comparison (`<`) | -| `GreaterThan` | Greater than comparison (`>`) | -| `LessEqual` | Less than or equal comparison (`<=`) | -| `GreaterEqual` | Greater than or equal comparison (`>=`) | +| `LessThan` | Less than comparison (`<`) (added in v0.2.0) | +| `GreaterThan` | Greater than comparison (`>`) (added in v0.2.0) | +| `LessEqual` | Less than or equal comparison (`<=`) (added in v0.2.0) | +| `GreaterEqual` | Greater than or equal comparison (`>=`) (added in v0.2.0) | | `BitwiseAnd` | Bitwise AND (`&`) | | `BitwiseAndMask(u64)` | Bitwise AND with mask value | +**Version Note:** The comparison operators `LessThan`, `GreaterThan`, `LessEqual`, and `GreaterEqual` were added in v0.2.0. + #### Value Value types for matching. diff --git a/docs/src/api-reference.md b/docs/src/api-reference.md index 3ee6d559..4da2115f 100644 --- a/docs/src/api-reference.md +++ b/docs/src/api-reference.md @@ -223,7 +223,7 @@ use libmagic_rs::TypeKind; | Variant | Description | |---------|-------------| -| `Byte { signed }` | Single byte with explicit signedness | +| `Byte { signed }` | Single byte with explicit signedness (struct variant since v0.2.0; previously unit variant) | | `Short { endian, signed }` | 16-bit integer | | `Long { endian, signed }` | 32-bit integer | | `String { max_length }` | String data | @@ -240,10 +240,10 @@ use libmagic_rs::Operator; |---------|-------------| | `Equal` | Equality comparison (`=`) | | `NotEqual` | Inequality comparison (`!=`) | -| `LessThan` | Less than comparison (`<`) | -| `GreaterThan` | Greater than comparison (`>`) | -| `LessEqual` | Less than or equal comparison (`<=`) | -| `GreaterEqual` | Greater than or equal comparison (`>=`) | +| `LessThan` | Less than comparison (`<`) (added in v0.2.0) | +| `GreaterThan` | Greater than comparison (`>`) (added in v0.2.0) | +| `LessEqual` | Less than or equal comparison (`<=`) (added in v0.2.0) | +| `GreaterEqual` | Greater than or equal comparison (`>=`) (added in v0.2.0) | | `BitwiseAnd` | Bitwise AND | | `BitwiseAndMask(u64)` | Bitwise AND with mask | @@ -477,6 +477,12 @@ pub use error::{EvaluationError, LibmagicError, ParseError}; - **Minimum Rust Version**: 1.85 - **Edition**: 2024 - **License**: Apache-2.0 +- **Current Version**: 0.2.0 + +### Breaking Changes in v0.2.0 + +- `TypeKind::Byte` changed from a unit variant to a struct variant `Byte { signed }` to support explicit signedness +- Added comparison operators: `LessThan`, `GreaterThan`, `LessEqual`, `GreaterEqual` to the `Operator` enum (breaking change due to exhaustive enum) For complete API documentation with examples, run: diff --git a/docs/src/ast-structures.md b/docs/src/ast-structures.md index eab4b483..f821b183 100644 --- a/docs/src/ast-structures.md +++ b/docs/src/ast-structures.md @@ -164,6 +164,8 @@ let from_end = OffsetSpec::FromEnd(-16); The `TypeKind` enum specifies how to interpret bytes at the given offset: +> **Breaking Change in v0.2.0:** The `Byte` variant changed from a unit variant (`Byte`) to a struct variant (`Byte { signed: bool }`). Code that pattern-matches exhaustively on `TypeKind` requires updates. + ### Numeric Types ```rust @@ -236,6 +238,8 @@ pub enum Operator { } ``` +> **Added in v0.2.0:** The comparison operators `LessThan`, `GreaterThan`, `LessEqual`, and `GreaterEqual` were added. This is a breaking change for exhaustive matches on `Operator`. + **Usage Examples:** ```rust diff --git a/docs/src/evaluator.md b/docs/src/evaluator.md index 7d63e10e..78c18359 100644 --- a/docs/src/evaluator.md +++ b/docs/src/evaluator.md @@ -90,7 +90,7 @@ pub fn resolve_offset( Interprets bytes according to type specifications: -- **Byte**: Single byte values +- **Byte**: Single byte values (signed or unsigned) - **Short**: 16-bit integers with endianness - **Long**: 32-bit integers with endianness - **String**: Byte sequences with length limits @@ -104,16 +104,18 @@ pub fn read_typed_value( ) -> Result ``` +The `read_byte` function signature changed in v0.2.0 to accept three parameters (`buffer`, `offset`, and `signed`) instead of two, allowing explicit control over signed vs unsigned byte interpretation. + ### Operator Application (`evaluator/operators.rs`) Applies comparison operations: - **Equal** (`=`, `==`): Exact value matching - **NotEqual** (`!=`, `<>`): Non-matching values -- **LessThan** (`<`): Less-than comparison (numeric or lexicographic) -- **GreaterThan** (`>`): Greater-than comparison (numeric or lexicographic) -- **LessEqual** (`<=`): Less-than-or-equal comparison (numeric or lexicographic) -- **GreaterEqual** (`>=`): Greater-than-or-equal comparison (numeric or lexicographic) +- **LessThan** (`<`): Less-than comparison (numeric or lexicographic) *(added in v0.2.0)* +- **GreaterThan** (`>`): Greater-than comparison (numeric or lexicographic) *(added in v0.2.0)* +- **LessEqual** (`<=`): Less-than-or-equal comparison (numeric or lexicographic) *(added in v0.2.0)* +- **GreaterEqual** (`>=`): Greater-than-or-equal comparison (numeric or lexicographic) *(added in v0.2.0)* - **BitwiseAnd** (`&`): Pattern matching for flags - **BitwiseAndMask**: AND with mask then compare @@ -127,6 +129,34 @@ pub fn apply_operator( ) -> bool ``` +**Example with comparison operators:** + +```rust +use libmagic_rs::parser::ast::{Operator, Value}; +use libmagic_rs::evaluator::operators::apply_operator; + +// Less-than comparison (v0.2.0+) +assert!(apply_operator( + &Operator::LessThan, + &Value::Uint(5), + &Value::Uint(10) +)); + +// Greater-than-or-equal comparison (v0.2.0+) +assert!(apply_operator( + &Operator::GreaterEqual, + &Value::Uint(10), + &Value::Uint(10) +)); + +// Cross-type integer comparison (v0.2.0+) +assert!(apply_operator( + &Operator::LessThan, + &Value::Int(-1), + &Value::Uint(0) +)); +``` + ## Evaluation Algorithm The evaluator uses a depth-first hierarchical algorithm: @@ -292,6 +322,26 @@ for m in matches { } ``` +**Example with comparison operators (v0.2.0+):** + +```rust +use libmagic_rs::{evaluate_rules, EvaluationConfig}; +use libmagic_rs::parser::parse_text_magic_file; + +// Parse magic rule with comparison operator +let magic_content = r#" +0 leshort <100 Small value detected +0 leshort >=1000 Large value detected +"#; +let rules = parse_text_magic_file(magic_content)?; + +let buffer = vec![0x0A, 0x00]; // Little-endian 10 +let matches = evaluate_rules(&rules, &buffer)?; + +// Matches first rule (<100) +assert_eq!(matches[0].message, "Small value detected"); +``` + ## Implementation Status - [x] Basic evaluation engine structure diff --git a/docs/src/migration.md b/docs/src/migration.md index 060ce1ed..9c48f2c1 100644 --- a/docs/src/migration.md +++ b/docs/src/migration.md @@ -185,6 +185,106 @@ libmagic-rs aims to maintain compatibility with: - **GNU file output**: Text output format compatibility - **Common use cases**: Drop-in replacement for most applications +## Migrating from v0.1.x to v0.2.0 + +Version 0.2.0 introduces breaking changes to support comparison operators and improve type handling. Update your code as follows: + +### TypeKind::Byte Variant Change + +The `Byte` variant changed from a unit variant to a struct variant with a `signed` field. + +**Before (v0.1.x):** + +```rust,ignore +use libmagic_rs::parser::ast::TypeKind; + +match type_kind { + TypeKind::Byte => { + // Handle byte type + } + _ => {} +} + +// Constructing +let byte_type = TypeKind::Byte; +``` + +**After (v0.2.0):** + +```rust,ignore +use libmagic_rs::parser::ast::TypeKind; + +match type_kind { + TypeKind::Byte { signed } => { + // Handle byte type, check signedness if needed + if signed { + // Handle signed byte + } else { + // Handle unsigned byte + } + } + _ => {} +} + +// Constructing +let signed_byte = TypeKind::Byte { signed: true }; +let unsigned_byte = TypeKind::Byte { signed: false }; +``` + +### New Operator Variants + +The `Operator` enum added four comparison operators. Exhaustive matches must handle these variants. + +**Before (v0.1.x):** + +```rust,ignore +use libmagic_rs::parser::ast::Operator; + +match operator { + Operator::Equal => { /* ... */ } + Operator::NotEqual => { /* ... */ } + // Other existing variants +} +``` + +**After (v0.2.0):** + +```rust,ignore +use libmagic_rs::parser::ast::Operator; + +match operator { + Operator::Equal => { /* ... */ } + Operator::NotEqual => { /* ... */ } + Operator::LessThan => { /* ... */ } + Operator::GreaterThan => { /* ... */ } + Operator::LessEqual => { /* ... */ } + Operator::GreaterEqual => { /* ... */ } + // Other existing variants +} +``` + +### read_byte Function Signature + +The `libmagic_rs::evaluator::types::read_byte` function signature changed from 2 to 3 parameters. + +**Before (v0.1.x):** + +```rust,ignore +use libmagic_rs::evaluator::types::read_byte; + +let value = read_byte(buffer, offset)?; +``` + +**After (v0.2.0):** + +```rust,ignore +use libmagic_rs::evaluator::types::read_byte; + +// The third parameter indicates signedness +let signed_value = read_byte(buffer, offset, true)?; +let unsigned_value = read_byte(buffer, offset, false)?; +``` + ## Getting Help If you encounter migration issues: diff --git a/docs/src/parser.md b/docs/src/parser.md index df60c628..29f3919b 100644 --- a/docs/src/parser.md +++ b/docs/src/parser.md @@ -70,7 +70,7 @@ parse_operator("==") // Ok(("", Operator::Equal)) parse_operator("!=") // Ok(("", Operator::NotEqual)) parse_operator("<>") // Ok(("", Operator::NotEqual)) -// Comparison operators +// Comparison operators (v0.2.0+) parse_operator("<") // Ok(("", Operator::LessThan)) parse_operator(">") // Ok(("", Operator::GreaterThan)) parse_operator("<=") // Ok(("", Operator::LessEqual)) @@ -88,6 +88,8 @@ parse_operator("&") // Ok(("", Operator::BitwiseAnd)) - ✅ Invalid operator rejection with clear errors - ✅ Eight comparison and bitwise operators supported +**Note:** Comparison operators (`<`, `>`, `<=`, `>=`) were implemented in v0.2.0 via [#104](https://github.com/EvilBit-Labs/libmagic-rs/pull/104). + ### Value Parsing (`parse_value`) Handles multiple value types with intelligent type detection: