Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions DisCatSharp/Net/Rest/DiscordApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3899,13 +3899,16 @@ internal async Task<DiscordInvite> CreateChannelInviteAsync(ulong channelId, int
var ret = DiscordJson.DeserializeObject<DiscordInvite>(res.Response, this.Discord);
ret.Discord = this.Discord;

try
{
targetUsersCsv?.Stream.Dispose();
}
catch
if (targetUsersCsv is not null && targetUsersCsv.ResetPositionTo is null)
{
// ignore
try
{
targetUsersCsv.Stream.Dispose();
Comment on lines +3902 to +3906

Choose a reason for hiding this comment

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

P2 Badge Avoid disposing user-owned non-seekable streams

This disposal guard treats ResetPositionTo == null as “internally owned,” but user-supplied streams that are not seekable also produce ResetPositionTo == null in CreateTargetUsersFile. In that case, the caller’s stream will still be disposed here, which contradicts the intent of preserving caller ownership and can still trigger ObjectDisposedException if the caller reuses the stream after CreateChannelInviteAsync. Consider tracking ownership separately (e.g., a flag from the targetUsersFile parameter) rather than relying on ResetPositionTo alone.

Useful? React with 👍 / 👎.

}
catch
{
// ignore
}
}

return ret;
Expand Down Expand Up @@ -5152,13 +5155,16 @@ internal async Task UpdateInviteTargetUsersAsync(string inviteCode, Stream? targ

if (targetUsersCsv.ResetPositionTo is not null)
targetUsersCsv.Stream.Position = targetUsersCsv.ResetPositionTo.Value;
try
{
targetUsersCsv.Stream.Dispose();
}
catch
else if (targetUsersCsv is not null)
{
// ignore
try
{
Comment on lines +5158 to +5161

Choose a reason for hiding this comment

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

P2 Badge Avoid disposing user-owned non-seekable streams

This disposal path still closes user-owned streams that are not seekable because CreateTargetUsersFile sets ResetPositionTo only when stream.CanSeek is true. For non-seekable caller streams, ResetPositionTo remains null and this block disposes them anyway, defeating the ownership fix and risking ObjectDisposedException for callers who reuse the stream after UpdateInviteTargetUsersAsync completes.

Useful? React with 👍 / 👎.

targetUsersCsv.Stream.Dispose();
}
catch
{
// ignore
}
}
}

Expand Down
Loading