-
-
Notifications
You must be signed in to change notification settings - Fork 397
fix: prevent media processing failures from aborting webhook delivery #266
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -839,6 +839,7 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { | |
| // try to get Image if any | ||
| img := evt.Message.GetImageMessage() | ||
| if img != nil { | ||
| func() { | ||
| // Create a temporary directory in /tmp | ||
| tmpDirectory := filepath.Join("/tmp", "user_"+txtid) | ||
| errDir := os.MkdirAll(tmpDirectory, 0751) | ||
|
|
@@ -916,11 +917,13 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { | |
| } else { | ||
| log.Info().Str("path", tmpPath).Msg("Temporary file deleted") | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| // try to get Audio if any | ||
| audio := evt.Message.GetAudioMessage() | ||
| if audio != nil { | ||
| func() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Create a temporary directory in /tmp | ||
| tmpDirectory := filepath.Join("/tmp", "user_"+txtid) | ||
| errDir := os.MkdirAll(tmpDirectory, 0751) | ||
|
|
@@ -1004,11 +1007,13 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { | |
| } else { | ||
| log.Info().Str("path", tmpPath).Msg("Temporary file deleted") | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| // try to get Document if any | ||
| document := evt.Message.GetDocumentMessage() | ||
| if document != nil { | ||
| func() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Create a temporary directory in /tmp | ||
| tmpDirectory := filepath.Join("/tmp", "user_"+txtid) | ||
| errDir := os.MkdirAll(tmpDirectory, 0751) | ||
|
|
@@ -1097,11 +1102,13 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { | |
| } else { | ||
| log.Info().Str("path", tmpPath).Msg("Temporary file deleted") | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| // try to get Video if any | ||
| video := evt.Message.GetVideoMessage() | ||
| if video != nil { | ||
| func() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Create a temporary directory in /tmp | ||
| tmpDirectory := filepath.Join("/tmp", "user_"+txtid) | ||
| errDir := os.MkdirAll(tmpDirectory, 0751) | ||
|
|
@@ -1179,10 +1186,12 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { | |
| } else { | ||
| log.Info().Str("path", tmpPath).Msg("Temporary file deleted") | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| sticker := evt.Message.GetStickerMessage() | ||
| if sticker != nil { | ||
| func() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| tmpDirectory := filepath.Join("/tmp", "user_"+txtid) | ||
| errDir := os.MkdirAll(tmpDirectory, 0751) | ||
| if errDir != nil { | ||
|
|
@@ -1253,6 +1262,7 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { | |
| if err := os.Remove(tmpPath); err != nil { | ||
| log.Error().Err(err).Msg("Failed to delete temporary file") | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While wrapping this block in a closure prevents the main event handler from aborting on error, the implementation inside (specifically line 860) is susceptible to a panic if
mime.ExtensionsByTypereturns an empty slice (which happens for unknown or empty MIME types). Additionally, any earlyreturnwithin this closure (e.g., at line 901) will bypass theos.Remove(tmpPath)call at line 914, leading to temporary file leaks in/tmp. It is recommended to usedefer os.Remove(tmpPath)once the path is determined to ensure cleanup regardless of how the closure exits.