From d45abb631bd1c93ca15410f993baee017d06e964 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 11 Jun 2026 10:52:10 -0600 Subject: [PATCH] OMF quality pass - Format with rustfmt; fix clippy lints - Add module documentation - Reject invalid record types instead of silently skipping - Recognize the DWARF segment class as debug sections - Add read_core,omf to the feature test matrix --- src/read/omf/file.rs | 7 +++++-- src/read/omf/mod.rs | 14 +++++++++++++- src/read/omf/relocation.rs | 4 ++-- src/read/omf/segment.rs | 4 ++-- xtask/src/main.rs | 1 + 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/read/omf/file.rs b/src/read/omf/file.rs index 1e4c659..4dd0a0f 100644 --- a/src/read/omf/file.rs +++ b/src/read/omf/file.rs @@ -7,7 +7,7 @@ use crate::read::{ Object, ObjectKind, ObjectSection, ReadRef, Result, SectionIndex, SectionKind, SymbolIndex, SymbolKind, }; -use crate::{omf, SubArchitecture}; +use crate::{SubArchitecture, omf}; use super::{ OmfComdat, OmfComdatData, OmfComdatIterator, OmfComdatSelection, OmfDataChunk, OmfFixup, @@ -282,7 +282,10 @@ impl<'data, R: ReadRef<'data>> OmfFile<'data, R> { break; } _ => { - // Skip unknown record types + if !omf::record_type::is_valid(record_type) { + return Err(Error("Invalid OMF record type")); + } + // Skip unhandled record types (e.g. LINNUM, LINSYM) } } diff --git a/src/read/omf/mod.rs b/src/read/omf/mod.rs index 756900f..8a4c972 100644 --- a/src/read/omf/mod.rs +++ b/src/read/omf/mod.rs @@ -1,4 +1,16 @@ -//! Support for reading OMF files. +//! Support for reading OMF (Relocatable Object Module Format) files. +//! +//! OMF is the object file format used by most DOS and early Windows +//! compilers, such as Borland C++ and Open Watcom. Both 16-bit and 32-bit +//! variants are supported, including vendor extensions such as COMDAT +//! records and Borland virtual segments. +//! +//! [`OmfFile`] implements the [`Object`](crate::read::Object) trait for +//! OMF files. +//! +//! OMF doesn't have a notion of sections; instead, data is contributed to +//! segments (`SEGDEF`) and COMDATs. This implementation maps both to +//! sections in the unified read API. mod comdat; pub use comdat::*; diff --git a/src/read/omf/relocation.rs b/src/read/omf/relocation.rs index c5e4864..dd656a4 100644 --- a/src/read/omf/relocation.rs +++ b/src/read/omf/relocation.rs @@ -1,7 +1,7 @@ use crate::read::ReadRef; use crate::{ - omf, Relocation, RelocationEncoding, RelocationFlags, RelocationKind, RelocationTarget, - SectionIndex, + Relocation, RelocationEncoding, RelocationFlags, RelocationKind, RelocationTarget, + SectionIndex, omf, }; use super::{FrameMethod, OmfFile, TargetMethod}; diff --git a/src/read/omf/segment.rs b/src/read/omf/segment.rs index 3c6555f..3fb25bd 100644 --- a/src/read/omf/segment.rs +++ b/src/read/omf/segment.rs @@ -1,9 +1,9 @@ use alloc::vec::Vec; use crate::read::{self, Error, ObjectSegment, ReadRef, Result, SectionKind}; -use crate::{omf, Permissions, SegmentFlags}; +use crate::{Permissions, SegmentFlags, omf}; -use super::{expand_iterated_data, iterated_data_expanded_len, OmfFile, OmfFixup}; +use super::{OmfFile, OmfFixup, expand_iterated_data, iterated_data_expanded_len}; /// A section in an OMF file. /// diff --git a/xtask/src/main.rs b/xtask/src/main.rs index f8499e6..f24f02e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -130,6 +130,7 @@ fn cmd_features() -> Result<(), DynError> { "read_core,write_core,coff", "read_core,write_core,build_core,elf", "read_core,write_core,macho", + "read_core,omf", "read_core,write_core,pe", "read_core,write_core,xcoff", "read_core,wasm",