DsFileReader Seek issue with values >= (2^63 - 2^10)

조회 수: 2 (최근 30일)
Smattering_Applause
Smattering_Applause 2022년 2월 28일
댓글: Smattering_Applause 2024년 2월 5일
I am using DsFileReader to read .mf4 files (ASAM MDF spec files).
One of my files has some corrupted values that return locations well outside the range. Strangely, when calling seek(), DSFileReader can handle them until the value exceeds (2^63-2^10-1). For reference, this file claimes the size is 141397456 (under 2^27). If I try to seek to (2^63 - 2^10) then it will fail.
When the error occurs, I get ByteStreamSeekFailure: iostream stream error. This error is not caught by any Try/Catch, and doesn't have a code, so tracking down the issue is much tougher. I have managed to track it to the call of fr.Stream.seek(bytes, originNum); within the seekWithParsedInputs() function, and I can see the Stream is created as a matlab.io.internal.vfs.stream object, but those files don't appear browsable.
While I know my file is corrupted, I wanted to understand when to expect this non-trackable error so I can make sure any fix for where I am seeking will work and send a proper error before this non-sourced error. (also it's odd that 2^64-2^10 is the magic error threshold, I think it has to do with the biggest integer below 64 bits that Double can represent)

채택된 답변

Pratyush
Pratyush 2024년 2월 5일
Hi,
The issue you're facing with "DsFileReader" when seeking to a position "(2^63 - 2^10)" in a .mf4 file is likely due to limitations in MATLAB's floating-point representation and the underlying stream's capability. MATLAB can exactly represent integers up to "2^53 - 1" with double-precision floating-point numbers, and seeking beyond the limits of the stream can cause a "ByteStreamSeekFailure" error, which is not catchable with a try/catch block.
To handle this, you should:
  • Ensure the seek position is within the actual file size.
  • Use 64-bit integers (`int64`) for file positions to avoid floating-point inaccuracies.
  • Implement a wrapper function for the seek operation that checks the validity of the seek position before attempting to seek.
  • If necessary, contact the vendor for support or consult the documentation for proprietary functions like `DsFileReader`.
Hope this helps.
  댓글 수: 1
Smattering_Applause
Smattering_Applause 2024년 2월 5일
Reading the file size from the reader object is easy:
fileReader = matlab.io.datastore.DsFileReader(filefullpath);
fileReader.size
Then the target memory length / position can be compared to the file start/size to determine if in bounds. this will also catch cases where file saving errors generated a false number tha's less that 2^53-1 but still outside file size.
Using int64 might work however it wouldn't protect for the values being outside the file size.
So basically the wrapper function is the way I went, put in a few protections before calling read().
Ideally Mathwortks replies and says "we'll make an error handling", but otherwise your answer is as basically as good as we'll get.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vehicle Network Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by