Skip to content

Commit

Permalink
Return a value from data_position when the cursor is at the value end.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ColinFinck committed Mar 8, 2022
1 parent 61d13c6 commit a063e4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/attribute_value/non_resident.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Colin Finck <colin@reactos.org>
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// 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).
Expand Down Expand Up @@ -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<u64> {
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
Expand Down
4 changes: 2 additions & 2 deletions src/attribute_value/resident.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Colin Finck <colin@reactos.org>
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// 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.
Expand Down Expand Up @@ -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<u64> {
if self.stream_position < self.len() {
if self.stream_position <= self.len() {
Some(self.position + self.stream_position)
} else {
None
Expand Down

0 comments on commit a063e4a

Please sign in to comment.