You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/10/27 15:33:12 UTC

(incubator-opendal) 08/14: Fix seek check

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch lazy-reader
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 0dfe270b56ed9f12130537bc279a9d41fbb9a814
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Fri Oct 27 21:15:13 2023 +0800

    Fix seek check
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 core/src/raw/oio/read/file_read.rs | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/core/src/raw/oio/read/file_read.rs b/core/src/raw/oio/read/file_read.rs
index ca95691ea..9bf363d39 100644
--- a/core/src/raw/oio/read/file_read.rs
+++ b/core/src/raw/oio/read/file_read.rs
@@ -268,6 +268,13 @@ where
 
                 let pos = Self::calculate_position(self.offset, self.size, self.cur, pos)?;
                 let cur = ready!(r.poll_seek(cx, pos))?;
+                if cur < self.offset.unwrap() {
+                    return Poll::Ready(Err(Error::new(
+                        ErrorKind::InvalidInput,
+                        "seek to a negative position is invalid",
+                    )
+                    .with_context("position", format!("{pos:?}"))));
+                }
                 self.cur = cur - self.offset.unwrap();
                 Poll::Ready(Ok(self.cur))
             }
@@ -394,6 +401,14 @@ where
 
                 let pos = Self::calculate_position(self.offset, self.size, self.cur, pos)?;
                 let cur = r.seek(pos)?;
+                if cur < self.offset.unwrap() {
+                    return Err(Error::new(
+                        ErrorKind::InvalidInput,
+                        "seek to a negative position is invalid",
+                    )
+                    .with_context("position", format!("{pos:?}")));
+                }
+
                 self.cur = cur - self.offset.unwrap();
                 Ok(self.cur)
             }