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

2 visualizaciones (últimos 30 días)
Smattering_Applause
Smattering_Applause el 28 de Feb. de 2022
Comentada: Smattering_Applause el 5 de Feb. de 2024
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)

Respuesta aceptada

Pratyush
Pratyush el 5 de Feb. de 2024
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 comentario
Smattering_Applause
Smattering_Applause el 5 de Feb. de 2024
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by