From a063e4a21d0e08ea21b4619dc9c0459279a1f796 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Tue, 8 Mar 2022 18:43:01 +0100 Subject: [PATCH] Return a value from `data_position` when the cursor is at the value end. For resident attributes, this coincidentally adds support for zero-sized attribute structured values. I'm not (yet) aware of zero-sized Data Runs in non-resident attributes, but it's important to implement `data_position` consistently for all attribute types. Finally fixes #9 --- src/attribute_value/non_resident.rs | 4 ++-- src/attribute_value/resident.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/attribute_value/non_resident.rs b/src/attribute_value/non_resident.rs index 9749a7f..75fdc0a 100644 --- a/src/attribute_value/non_resident.rs +++ b/src/attribute_value/non_resident.rs @@ -1,4 +1,4 @@ -// Copyright 2021 Colin Finck +// Copyright 2021-2022 Colin Finck // SPDX-License-Identifier: MIT OR Apache-2.0 // //! This module implements a reader for a non-resident attribute value (that is not part of an Attribute List). @@ -456,7 +456,7 @@ impl NtfsDataRun { /// * The current seek position is outside the valid range, or /// * The Data Run is a "sparse" Data Run pub fn data_position(&self) -> Option { - if self.position > 0 && self.stream_position < self.allocated_size() { + if self.position > 0 && self.stream_position <= self.allocated_size() { Some(self.position + self.stream_position) } else { None diff --git a/src/attribute_value/resident.rs b/src/attribute_value/resident.rs index 65d8878..7cc8481 100644 --- a/src/attribute_value/resident.rs +++ b/src/attribute_value/resident.rs @@ -1,4 +1,4 @@ -// Copyright 2021 Colin Finck +// Copyright 2021-2022 Colin Finck // SPDX-License-Identifier: MIT OR Apache-2.0 // //! This module implements a reader for a value that is already in memory and can therefore be accessed via a slice. @@ -43,7 +43,7 @@ impl<'f> NtfsResidentAttributeValue<'f> { /// Returns the absolute current data seek position within the filesystem, in bytes. /// This may be `None` if the current seek position is outside the valid range. pub fn data_position(&self) -> Option { - if self.stream_position < self.len() { + if self.stream_position <= self.len() { Some(self.position + self.stream_position) } else { None