@@ -204,4 +204,32 @@ TEST(JindoFileSystemAsyncReadTest, TestConcurrentReadAsyncAndReadFromOss) {
204204 }
205205}
206206
207+ TEST_F (JindoFileSystemTest, TestOpenWithKnownFileSizeReadsBackContent) {
208+ const std::string content = " abcdefghijk" ;
209+ const std::string file_path = test_dir_ + " file.data" ;
210+ ASSERT_OK (fs_->WriteFile (file_path, content, /* overwrite=*/ true ));
211+
212+ // The read path hands Open a length it already trusts; the stream must still serve the
213+ // object's real bytes, not just echo the length back.
214+ ASSERT_OK_AND_ASSIGN (auto in_stream,
215+ fs_->Open (FileStatus (file_path, static_cast <int64_t >(content.size ()))));
216+ ASSERT_OK_AND_ASSIGN (int64_t length, in_stream->Length ());
217+ ASSERT_EQ (length, static_cast <int64_t >(content.size ()));
218+ std::string read_content (content.size (), ' \0 ' );
219+ ASSERT_OK_AND_ASSIGN (int64_t read_len,
220+ in_stream->Read (read_content.data (), read_content.size ()));
221+ ASSERT_EQ (read_len, static_cast <int64_t >(content.size ()));
222+ ASSERT_EQ (content, read_content);
223+ ASSERT_OK (in_stream->Close ());
224+
225+ // A stale length shorter than the object must never yield bytes beyond what it vouches
226+ // for: the wrapper read is all-or-nothing, so over-reading the declared length fails with
227+ // an EOF error instead of silently returning truncated data.
228+ const int64_t short_length = static_cast <int64_t >(content.size ()) - 3 ;
229+ ASSERT_OK_AND_ASSIGN (auto short_stream, fs_->Open (FileStatus (file_path, short_length)));
230+ std::string short_read (content.size (), ' \0 ' );
231+ ASSERT_NOK_WITH_MSG (short_stream->Read (short_read.data (), short_read.size ()), " EOF reached" );
232+ ASSERT_OK (short_stream->Close ());
233+ }
234+
207235} // namespace paimon::jindo::test
0 commit comments