[Bug] H5Eget_msg corrupts memory

Hello!

According to http://www.hdfgroup.org/HDF5/doc/H5.user/Errors.html, H5Ewalk_cb example, one should use H5Eget_major/H5Eget_minor procedures to retrieve error information during custom stack traversal. However http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-GetMajor says "This function has been deprecated"; I believe one needs to use H5Eget_msg instead.

I've tried to implement custom error stack traversal. In attachment is a minimal example test.dpr which can be compiled with FreePascal. Whaen I run the program I get corrupted values in err_desc^.desc:

Major: File accessibilty
Minor: Unable to open file
ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■
:smiling_face:▌v-#▲:slight_smile:↑ minor: Unable to open file
ne 343 in H5FD_sec2_open(): unable to open file: name = 'non-existent.hdf', errn
o = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
Ён║лллллллл line 1585 in ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю
■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■☺▌v-#▲☻↑ minor: Unab
le to open file
ne 343 in H5FD_sec2_open(): unable to open file: name = 'non-existent.hdf', errn
o = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
Ён║лллллллл: ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■☺▌v-#▲☻↑ minor: Unable t
o open file
ne 343 in H5FD_sec2_open(): unable to open file: name = 'non-existent.hdf', errn
o = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
Ён║лллллллл

However if I comment out the following lines, err_desc^.desc stays valid:

//H5Eget_msg(err_desc^.maj_num, @Typ, @Buf, Length(Buf));
//WriteLn(Format('Major: %s', [String(Buf)]));
//H5Eget_msg(err_desc^.min_num, @Typ, @Buf, Length(Buf));
//WriteLn(Format('Minor: %s', [String(Buf)]));

yields

..\..\src\H5F.c line 1585 in H5Fopen: unable to open file

It seems that H5Eget_msg is the culprit.

Please CC paramon@acdlabs.ru if answering this message.

I'm ready to provide any additional info,
Andrey Paramonov

test.dpr (1.83 KB)

···

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Hi all,
stack as (I think) this causes the stack to be reset. This invalidates the
current traversal and produces rubbish data after that point. I have seen
exactly the same behaviour in C with including/excluding the H5Eget_msg
call - my work-around is to record the major/minor numbers for look-up
after the stack traversal is complete. This is somewhat undesirable and it
seems unintuitive that H5Eget_msg should fail in such a way.

Cheers,
Martijn

···

From my experience, you cannot call H5Eget_msg while traversing the error

On 24 March 2014 17:38, Андрей Парамонов <paramon@acdlabs.ru> wrote:

Hello!

According to http://www.hdfgroup.org/HDF5/doc/H5.user/Errors.html,
H5Ewalk_cb example, one should use H5Eget_major/H5Eget_minor procedures to
retrieve error information during custom stack traversal. However
http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-GetMajor says "This
function has been deprecated"; I believe one needs to use H5Eget_msg
instead.

I've tried to implement custom error stack traversal. In attachment is a
minimal example test.dpr which can be compiled with FreePascal. Whaen I run
the program I get corrupted values in err_desc^.desc:

Major: File accessibilty
Minor: Unable to open file
ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■
ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■
:slight_smile:▌v-#▲:slight_smile:↑ minor: Unable to open file
ne 343 in H5FD_sec2_open(): unable to open file: name =
'non-existent.hdf', errn
o = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
Ён║лллллллл line 1585 in ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■
ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю
■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■☺▌v-#▲☻↑ minor:
Unab
le to open file
ne 343 in H5FD_sec2_open(): unable to open file: name =
'non-existent.hdf', errn
o = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
Ён║лллллллл: ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■ю■☺▌v-#▲☻↑ minor:
Unable t
o open file
ne 343 in H5FD_sec2_open(): unable to open file: name =
'non-existent.hdf', errn
o = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
Ён║лллллллл

However if I comment out the following lines, err_desc^.desc stays valid:

//H5Eget_msg(err_desc^.maj_num, @Typ, @Buf, Length(Buf));
//WriteLn(Format('Major: %s', [String(Buf)]));
//H5Eget_msg(err_desc^.min_num, @Typ, @Buf, Length(Buf));
//WriteLn(Format('Minor: %s', [String(Buf)]));

yields

..\..\src\H5F.c line 1585 in H5Fopen: unable to open file

It seems that H5Eget_msg is the culprit.

Please CC paramon@acdlabs.ru if answering this message.

I'm ready to provide any additional info,
Andrey Paramonov

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org

http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

We have used the H5E functions successfully in the hdf-java native library.
Also our java unit tests for the H5E functions could be useful.

Attached is the source for error handling in java.

Allen

exceptionImp.c (16.2 KB)

···

On Monday, March 24, 2014 11:03:31 AM Андрей Парамонов wrote:

24.03.2014 11:00, Martijn Jasperse пишет:
> Hi all,
>
> From my experience, you cannot call H5Eget_msg while traversing the
>
> error stack as (I think) this causes the stack to be reset. This
> invalidates the current traversal and produces rubbish data after that
> point. I have seen exactly the same behaviour in C with
> including/excluding the H5Eget_msg call - my work-around is to record
> the major/minor numbers for look-up after the stack traversal is
> complete. This is somewhat undesirable and it seems unintuitive that
> H5Eget_msg should fail in such a way.

Thank you for your feedback.
I propose that at least
http://www.hdfgroup.org/HDF5/doc/H5.user/Errors.html is fixed/updated
then, because now it somewhat misleading.

Best wishes,
Andrey Paramonov

24.03.2014 11:00, Martijn Jasperse пишет:

Hi all,
From my experience, you cannot call H5Eget_msg while traversing the
error stack as (I think) this causes the stack to be reset. This
invalidates the current traversal and produces rubbish data after that
point. I have seen exactly the same behaviour in C with
including/excluding the H5Eget_msg call - my work-around is to record
the major/minor numbers for look-up after the stack traversal is
complete. This is somewhat undesirable and it seems unintuitive that
H5Eget_msg should fail in such a way.

Thank you for your feedback.
I propose that at least http://www.hdfgroup.org/HDF5/doc/H5.user/Errors.html is fixed/updated then, because now it somewhat misleading.

Best wishes,
Andrey Paramonov

···

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Hi Allen, everyone,
As I understand it, you implement exactly what I suggest in my previous
message - your stack walking function "walk_error_callback" stores the
error numbers in a structure, which get turned into strings later. You
don't actually call H5Eget_msg inside the walk callback, but rather after
traversal is complete in "h5libraryError".

To clarify, it looks like calling H5Eget_msg *inside *the walk callback
corrupts the stack, but to my knowledge this is not documented anywhere and
is somewhat confusing behaviour. Perhaps H5Eget_msg could be changed to
have different error-handling behaviour, or the documentation should be
updated to explicitly point out it should not be used inside a stack
traversal.

More generally, would it be correct to say that the walk callback should
call *no *HDF5 function during traversal to ensure the problem does not
arise?

Cheers,
Martijn

···

On 25 March 2014 03:02, Allen Byrne <byrn@hdfgroup.org> wrote:

We have used the H5E functions successfully in the hdf-java native library.
Also our java unit tests for the H5E functions could be useful.

Attached is the source for error handling in java.

Allen

On Monday, March 24, 2014 11:03:31 AM Андрей Парамонов wrote:
> 24.03.2014 11:00, Martijn Jasperse пишет:
> > Hi all,
> >
> > From my experience, you cannot call H5Eget_msg while traversing the
> >
> > error stack as (I think) this causes the stack to be reset. This
> > invalidates the current traversal and produces rubbish data after that
> > point. I have seen exactly the same behaviour in C with
> > including/excluding the H5Eget_msg call - my work-around is to record
> > the major/minor numbers for look-up after the stack traversal is
> > complete. This is somewhat undesirable and it seems unintuitive that
> > H5Eget_msg should fail in such a way.
>
> Thank you for your feedback.
> I propose that at least
> http://www.hdfgroup.org/HDF5/doc/H5.user/Errors.html is fixed/updated
> then, because now it somewhat misleading.
>
> Best wishes,
> Andrey Paramonov