Skip to content

Add size message checks for logging #45892

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

Conversation

pvollan
Copy link
Contributor

@pvollan pvollan commented May 25, 2025

@pvollan pvollan self-assigned this May 25, 2025
@pvollan pvollan added the WebKit Process Model Bugs related to WebKit's multi-process architecture label May 25, 2025
@pvollan pvollan requested review from cdumez and szewai May 25, 2025 20:18
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 25, 2025
@pvollan pvollan removed the merging-blocked Applied to prevent a change from being merged label May 25, 2025
@pvollan pvollan force-pushed the eng/Add-size-message-checks-for-logging branch from 90e7561 to 303cb0f Compare May 25, 2025 20:52
if (type == OS_LOG_TYPE_FAULT)
type = OS_LOG_TYPE_ERROR;

if (char* messageString = os_log_copy_message_string(msg)) {
auto logString = unsafeSpan8IncludingNullTerminator(messageString);
WebProcess::singleton().sendLogOnStream(logChannel, logCategory, logString, type);
if (logString.size() < logStringMaxSize)
WebProcess::singleton().sendLogOnStream(logChannel, logCategory, logString, type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this affect WebRTC logging which can be quite long (but quite useful for debugging)?
Also, if a channel log is debug, I would expect logging to be high in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good point! Is there WebRTC logging in the WebContent process? If so, would you know the approximate size of the largest log string?

Thanks for reviewing!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the latest patch, I increased the max size of the log string to accommodate for this.

@pvollan pvollan requested a review from youennf May 29, 2025 19:12
@pvollan pvollan force-pushed the eng/Add-size-message-checks-for-logging branch from 303cb0f to 6330177 Compare May 30, 2025 14:54
if (type == OS_LOG_TYPE_FAULT)
type = OS_LOG_TYPE_ERROR;

if (char* messageString = os_log_copy_message_string(msg)) {
auto logString = unsafeSpan8IncludingNullTerminator(messageString);
WebProcess::singleton().sendLogOnStream(logChannel, logCategory, logString, type);
if (logString.size() < logStringMaxSize)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we truncate the string and send instead of dropping message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good point, will fix!

Thanks for reviewing!

@pvollan pvollan force-pushed the eng/Add-size-message-checks-for-logging branch from 6330177 to cde89e0 Compare May 30, 2025 21:27
@pvollan pvollan requested a review from szewai May 30, 2025 21:28
String logStringTruncated = String::fromUTF8(logString).left(logStringMaxSize - 1);
logString = byteCast<uint8_t>(logStringTruncated.utf8().spanIncludingNullTerminator());
WebProcess::singleton().sendLogOnStream(logChannel, logCategory, logString, type);
} else
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could move WebProcess::singleton().sendLogOnStream( out of if condition and remove else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good point, will fix.

Thanks for reviewing!

@pvollan pvollan force-pushed the eng/Add-size-message-checks-for-logging branch from cde89e0 to 5cb177a Compare June 28, 2025 23:57
@pvollan pvollan force-pushed the eng/Add-size-message-checks-for-logging branch 2 times, most recently from 9898373 to 63eb21a Compare June 30, 2025 14:41
@pvollan pvollan added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 30, 2025
https://bugs.webkit.org/show_bug.cgi?id=293558
rdar://152010794

Reviewed by Sihui Liu.

* Source/WebKit/Shared/LogStream.cpp:
(WebKit::LogStream::logOnBehalfOfWebContent):
* Source/WebKit/Shared/LogStream.h:
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::registerLogHook):

Canonical link: https://commits.webkit.org/296808@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Add-size-message-checks-for-logging branch from 63eb21a to 3a08604 Compare June 30, 2025 17:22
@webkit-commit-queue
Copy link
Collaborator

Committed 296808@main (3a08604): https://commits.webkit.org/296808@main

Reviewed commits have been landed. Closing PR #45892 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 3a08604 into WebKit:main Jun 30, 2025
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Process Model Bugs related to WebKit's multi-process architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants