Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer in iter_stream.h #2104

Closed
singerj opened this issue Aug 8, 2017 · 6 comments
Closed

Null pointer in iter_stream.h #2104

singerj opened this issue Aug 8, 2017 · 6 comments
Assignees
Labels
Projects
Milestone

Comments

@singerj
Copy link
Collaborator

singerj commented Aug 8, 2017

Dear all,

There seems to be an issue with the casting in iter_stream.h.

When applying the following patch:

--- seqan-seqan-v2.3.2/include/seqan/stream/iter_stream.h
+++ seqan-seqan-v2.3.2/include/seqan/stream/iter_stream.h
@@ -240,8 +240,9 @@
     {}
 
     Iter(TIStream & stream) :
-        streamBuf(static_cast<StreamBuffer<TValue> *>(stream.rdbuf()))
+        streamBuf(dynamic_cast<StreamBuffer<TValue> *>(stream.rdbuf()))
     {
+        printf("streamBuf: %p\n", streamBuf);
         stream.exceptions(std::ios_base::badbit);
     }
 

example
seqan/demos/tutorial/sam_and_bam_io/example1.cpp
will throw
streamBuf: (nil)

Best,
Jochen

@singerj
Copy link
Collaborator Author

singerj commented Aug 9, 2017

By the way, I tested it using g++-5.2.0 and g++-6.2.0

@smehringer
Copy link
Member

Hi @singerj,
we're sorry for answering so late but a lot of us are on vacation around this time.

Why do you need this patch?

Since StreamBuffer is a derived class of std::basic_istream, a dynamic_cast will always fail because you are "down casting", so a static_cast is the proper thing to do is it not?

@singerj
Copy link
Collaborator Author

singerj commented Aug 16, 2017

Hi @smehringer,

thanks for the reply. The code changes from above are not meant to be a patch, but much rather should only show the problem.

If I use -fsanitize=undefined,float-cast-overflow,float-divide-by-zero as compiler options for gcc(5.2.0/6.2.0) I get the following results on the original code:

seqan/2.1.1/include/seqan/stream/iter_stream.h:243:19: runtime error: downcast of address 0x7ffcbadd1198 which does not point to an object of type 'StreamBuffer'
0x7ffcbadd1198: note: object is of type 'std::basic_filebuf<char, std::char_traits<char> >'
 3a 7f 00 00  f8 00 5f 44 3a 7f 00 00  80 60 1b 01 00 00 00 00  80 60 1b 01 00 00 00 00  80 60 1b 01
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'std::basic_filebuf<char, std::char_traits<char> >'
seqan/2.1.1/include/seqan/stream/iter_stream.h:295:19: runtime error: downcast of address 0x7f3a445f6880 which does not point to an object of type 'StreamBuffer'
0x7f3a445f6880: note: object is of type '__gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >'
 00 00 00 00  38 fe 5e 44 3a 7f 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for '__gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >'
seqan/2.1.1/include/seqan/stream/iter_stream.h:662:5: runtime error: member call on address 0x7ffcbadd1198 which does not point to an object of type 'StreamBuffer'
0x7ffcbadd1198: note: object is of type 'std::basic_filebuf<char, std::char_traits<char> >'
 3a 7f 00 00  f8 00 5f 44 3a 7f 00 00  80 60 1b 01 00 00 00 00  84 60 1b 01 00 00 00 00  eb 61 1b 01
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'std::basic_filebuf<char, std::char_traits<char> >'
seqan/2.1.1/include/seqan/stream/iter_stream.h:136:32: runtime error: member call on address 0x7ffcbadd1198 which does not point to an object of type 'StreamBuffer'
0x7ffcbadd1198: note: object is of type 'std::basic_filebuf<char, std::char_traits<char> >'
 3a 7f 00 00  f8 00 5f 44 3a 7f 00 00  80 60 1b 01 00 00 00 00  84 60 1b 01 00 00 00 00  eb 61 1b 01
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'std::basic_filebuf<char, std::char_traits<char> >'
seqan/2.1.1/include/seqan/stream/iter_stream.h:139:13: runtime error: member call on address 0x7ffcbadd1198 which does not point to an object of type 'StreamBuffer'
0x7ffcbadd1198: note: object is of type 'std::basic_filebuf<char, std::char_traits<char> >'
 3a 7f 00 00  f8 00 5f 44 3a 7f 00 00  80 60 1b 01 00 00 00 00  84 60 1b 01 00 00 00 00  eb 61 1b 01
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'std::basic_filebuf<char, std::char_traits<char> >'
seqan/2.1.1/include/seqan/stream/iter_stream.h:514:5: runtime error: member call on address 0x7f3a445f6880 which does not point to an object of type 'StreamBuffer'
0x7f3a445f6880: note: object is of type '__gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >'
 00 00 00 00  38 fe 5e 44 3a 7f 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for '__gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >'
@HD	VN:1.3	SO:coordinate
@SQ	SN:ref	LN:45
@SQ	SN:ref2	LN:40
r001	163	ref	7	30	8M4I4M1D3M	=	37	39	TTAGATAAAGAGGATACTG	*	XX:B:S,12561,2,20,112
r002	0	ref	9	30	1S2I6M1P1I1P1I4M2I	*	0	0	AAAAGATAAGGGATAAA	*
r003	0	ref	9	30	5H6M	*	0	0	AGCTAA	*
r004	0	ref	16	30	6M14N1I5M	*	0	0	ATAGCTCTCAGC	*
r003	16	ref	29	30	6H5M	*	0	0	TAGGC	*
r001	83	ref	37	30	9M	=	7	-39	CAGCGCCAT	*

Note that this problem is also present in seqan2.3.2 and most likely in the develop branch as there are no code changes for the involved data types.

@singerj
Copy link
Collaborator Author

singerj commented Aug 29, 2017

Hi @smehringer,

are there any news?

Cheers,
Jochen

@h-2
Copy link
Member

h-2 commented Aug 30, 2017

Hey Jochen,

yeah, looks like something is broken. @temehi can you have a look at this? @rrahn will be coordinating another release of SeqAn2 in September, but right now many people are unavailable...

Best,
Hannes

@h-2 h-2 added this to the Release 2.4.0 milestone Aug 30, 2017
@h-2 h-2 added bug and removed question labels Aug 30, 2017
@SoapGentoo
Copy link
Contributor

@smehringer dynamic_cast is a superset of static_cast, and whenever static_cast is valid, so is dynamic_cast.

@rrahn rrahn self-assigned this Sep 18, 2017
@rrahn rrahn added this to ToDo in SeqAn Oct 4, 2017
rrahn added a commit to rrahn/seqan that referenced this issue Dec 5, 2017
h-2 added a commit that referenced this issue Dec 14, 2017
[FIXED-#2104] Fixes sanitiser issue with StreamBuffer implementation.
@rrahn rrahn closed this as completed Dec 14, 2017
rrahn added a commit to rrahn/seqan that referenced this issue Jan 11, 2018
rrahn pushed a commit to rrahn/seqan that referenced this issue Jan 11, 2018
[FIXED-seqan#2104] Fixes sanitiser issue with StreamBuffer implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
SeqAn
ToDo
Development

No branches or pull requests

6 participants