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

Drop virtual from private member functions of Decoder class #4027

Merged

Conversation

prabhat00155
Copy link
Contributor

Only SyncDecoder class inherits Decoder class and I don't see any of these functions(marked virtual) being overwritten there.
enableLogLevel() and logCallback() functions being marked virtual is causing segfault when we cast void * to Decoder * and then call these virtual functions. Objects of classes with virtual function have a VPTR data member pointing to the VTABLE. Since, we are type-casting to Decoder * here, I think it doesn't have that information and hence throwing SIGSEGV.
For more information, check T91816044(FB internal task).

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the classes are public, have you checked if anyone else inherits it outside of TorchVision (Github and FBcode)? What if we replace the reinterpret_cast with dynamic_cast and keep the fields virtual?

Edit:
Yeah that's not going to be a simple change:

decoder.cpp:106:17: error: 'void' is not a class type
      decoder = dynamic_cast<Decoder*>(context->opaque);
                ^                      ~~~~~~~~~~~~~~~

Dynamic casting is not going to happen if we use void* pointers all over the place. Also I don't see any other way to make the following method compile and maintaining readCallback virtual without changing the method signature and rewriting large parts of the code:

int Decoder::readFunction(void* opaque, uint8_t* buf, int size) {
Decoder* decoder = reinterpret_cast<Decoder*>(opaque);
if (decoder == nullptr) {
return 0;
}
return decoder->readCallback(buf, size);
}

@prabhat00155
Copy link
Contributor Author

Given that the classes are public, have you checked if anyone else inherits it outside of TorchVision (Github and FBcode)? What if we replace the reinterpret_cast with dynamic_cast and keep the fields virtual?

Edit:
Yeah that's not going to be a simple change:

decoder.cpp:106:17: error: 'void' is not a class type
      decoder = dynamic_cast<Decoder*>(context->opaque);
                ^                      ~~~~~~~~~~~~~~~

I have not checked on GitHub. Here is the diff to check tests in fbcode with this change: D28995387.

@datumbox
Copy link
Contributor

datumbox commented Jun 9, 2021

@prabhat00155 I was editing my reply as you were responding... That's the 2nd time this happens to me today. 😄 Check again...

@prabhat00155
Copy link
Contributor Author

Given that the classes are public, have you checked if anyone else inherits it outside of TorchVision (Github and FBcode)? What if we replace the reinterpret_cast with dynamic_cast and keep the fields virtual?

Edit:
Yeah that's not going to be a simple change:

decoder.cpp:106:17: error: 'void' is not a class type
      decoder = dynamic_cast<Decoder*>(context->opaque);
                ^                      ~~~~~~~~~~~~~~~

Dynamic casting is not going to happen if we use void* pointers all over the place. Also I don't see any other way to make the following method compile and maintaining readCallback virtual without changing the method signature and rewriting large parts of the code:

int Decoder::readFunction(void* opaque, uint8_t* buf, int size) {
Decoder* decoder = reinterpret_cast<Decoder*>(opaque);
if (decoder == nullptr) {
return 0;
}
return decoder->readCallback(buf, size);
}

Yeah, opaque is a void *.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@prabhat00155 prabhat00155 merged commit 6fc18d6 into pytorch:master Jun 9, 2021
@prabhat00155 prabhat00155 deleted the prabhat00155/fix_seg_fault branch June 9, 2021 18:33
facebook-github-bot pushed a commit that referenced this pull request Jun 14, 2021
…4027)

Reviewed By: fmassa

Differential Revision: D29097737

fbshipit-source-id: b317a34c7a0fa4dc77efbc05a54141c69bf3c1fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants