Null reference when disposing a Volume class #138

Closed
opened 2026-01-29 22:07:15 +00:00 by claunia · 8 comments
Owner

Originally created by @JasonBro on GitHub (Oct 3, 2016).

There's a new bit of code in the SharpCompress.Common.Volume class that causes a null exception when ReaderOptions is null (which it is by default).

Workround: Add a ReaderOptions in the Open(Stream, ReaderOptions) call.

    public void Dispose()
    {
        if (!ReaderOptions.LeaveStreamOpen && !disposed)
        {
            actualStream.Dispose();
            disposed = true;
        }
    }
Originally created by @JasonBro on GitHub (Oct 3, 2016). There's a new bit of code in the SharpCompress.Common.Volume class that causes a null exception when ReaderOptions is null (which it is by default). Workround: Add a ReaderOptions in the Open(Stream, ReaderOptions) call. ``` public void Dispose() { if (!ReaderOptions.LeaveStreamOpen && !disposed) { actualStream.Dispose(); disposed = true; } } ```
Author
Owner

@adamhathcock commented on GitHub (Oct 3, 2016):

Oh no. Thanks for reporting this. I'll fix it.

@adamhathcock commented on GitHub (Oct 3, 2016): Oh no. Thanks for reporting this. I'll fix it.
Author
Owner

@JasonBro commented on GitHub (Oct 3, 2016):

I know that feeling! I would have fixed it myself with a pull request, but
there might be other places that were changed as well.

I'm in no rush for the fix and it only took 2 minutes to find a work round.
Thanks for creating a great library.

Cheers

Jason

On 3 October 2016 at 13:22, Adam Hathcock notifications@github.com wrote:

Oh no. Thanks for reporting this. I'll fix it.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251092550,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABH6cZzxI5hNNvhXFNdMNBSp1exnHwV9ks5qwPOZgaJpZM4KMbsq
.

@JasonBro commented on GitHub (Oct 3, 2016): I know that feeling! I would have fixed it myself with a pull request, but there might be other places that were changed as well. I'm in no rush for the fix and it only took 2 minutes to find a work round. Thanks for creating a great library. Cheers Jason On 3 October 2016 at 13:22, Adam Hathcock notifications@github.com wrote: > Oh no. Thanks for reporting this. I'll fix it. > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251092550, > or mute the thread > https://github.com/notifications/unsubscribe-auth/ABH6cZzxI5hNNvhXFNdMNBSp1exnHwV9ks5qwPOZgaJpZM4KMbsq > .
Author
Owner

@adamhathcock commented on GitHub (Oct 3, 2016):

What archive format are you using? I was hoping that the options would never be null by the time it got to the Volume class.

@adamhathcock commented on GitHub (Oct 3, 2016): What archive format are you using? I was hoping that the options would never be null by the time it got to the `Volume` class.
Author
Owner

@JasonBro commented on GitHub (Oct 3, 2016):

This is the bit of code:-

using (var stream = await file.OpenAsync(FileAccess.Read))
{
using (var archive = SevenZipArchive.Open(stream))
{
...

On 3 October 2016 at 13:27, Adam Hathcock notifications@github.com wrote:

What archive format are you using? I was hoping that the options would
never be null by the time it got to the Volume class.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251093323,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABH6cTqhMky6i-2QoE43ImProHgBk_3fks5qwPS5gaJpZM4KMbsq
.

@JasonBro commented on GitHub (Oct 3, 2016): This is the bit of code:- using (var stream = await file.OpenAsync(FileAccess.Read)) { using (var archive = SevenZipArchive.Open(stream)) { ... On 3 October 2016 at 13:27, Adam Hathcock notifications@github.com wrote: > What archive format are you using? I was hoping that the options would > never be null by the time it got to the Volume class. > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251093323, > or mute the thread > https://github.com/notifications/unsubscribe-auth/ABH6cTqhMky6i-2QoE43ImProHgBk_3fks5qwPS5gaJpZM4KMbsq > .
Author
Owner

@adamhathcock commented on GitHub (Oct 3, 2016):

Thanks, found it. Also found another null issue while reviewing the code paths.

I wish I could mock test this stuff but not possible with this code :(

@adamhathcock commented on GitHub (Oct 3, 2016): Thanks, found it. Also found another null issue while reviewing the code paths. I wish I could mock test this stuff but not possible with this code :(
Author
Owner

@JasonBro commented on GitHub (Oct 3, 2016):

Besides, no matter how much you test it, someone will come up with ways of
using it you'd not thought of!

On 3 October 2016 at 13:34, Adam Hathcock notifications@github.com wrote:

Thanks, found it. Also found another null issue while reviewing the code
paths.

I wish I could mock test this stuff but not possible with this code :(

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251094513,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABH6cYLsqfJYQT3yNFBZlZ-t9rQE3lDtks5qwPZPgaJpZM4KMbsq
.

@JasonBro commented on GitHub (Oct 3, 2016): Besides, no matter how much you test it, someone will come up with ways of using it you'd not thought of! On 3 October 2016 at 13:34, Adam Hathcock notifications@github.com wrote: > Thanks, found it. Also found another null issue while reviewing the code > paths. > > I wish I could mock test this stuff but not possible with this code :( > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251094513, > or mute the thread > https://github.com/notifications/unsubscribe-auth/ABH6cYLsqfJYQT3yNFBZlZ-t9rQE3lDtks5qwPZPgaJpZM4KMbsq > .
Author
Owner

@adamhathcock commented on GitHub (Oct 3, 2016):

https://www.nuget.org/packages/sharpcompress/0.13.1

@adamhathcock commented on GitHub (Oct 3, 2016): https://www.nuget.org/packages/sharpcompress/0.13.1
Author
Owner

@JasonBro commented on GitHub (Oct 3, 2016):

Perfect! Thanks for your fast response. :-)

On 3 October 2016 at 13:51, Adam Hathcock notifications@github.com wrote:

https://www.nuget.org/packages/sharpcompress/0.13.1

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251097805,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABH6cYYj4CY2C9edCMhJLtwbHr2BmNrDks5qwPpTgaJpZM4KMbsq
.

@JasonBro commented on GitHub (Oct 3, 2016): Perfect! Thanks for your fast response. :-) On 3 October 2016 at 13:51, Adam Hathcock notifications@github.com wrote: > https://www.nuget.org/packages/sharpcompress/0.13.1 > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > https://github.com/adamhathcock/sharpcompress/issues/187#issuecomment-251097805, > or mute the thread > https://github.com/notifications/unsubscribe-auth/ABH6cYYj4CY2C9edCMhJLtwbHr2BmNrDks5qwPpTgaJpZM4KMbsq > .
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#138