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

Prevent truncating log tag name #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dextero
Copy link

@dextero dextero commented Feb 24, 2025

The currently hard-coded limit is 23 characters. This limit originates from the pre-Android 7.0 32-character limit on system property names, because Android's liblog allows setting the log level at runtime through log.tag system properties [1]. The limit meant that "log.tag.SOMETAG" must have been shorter than 32 bytes, leaving 23 bytes for the tag itself.

The system property length limitation was removed in [2], so since 2017 it no longer applies, and some Android components already use longer tags [3][4].

This change increases the size of the stack-allocated buffer used for null-terminating the tag to 128 bytes, and adds support for even longer tags by falling back to heap-allocated CString when the tag is longer than that. The fallback path will introduce a performance penalty, but at the same time will allow manual level adjustment via log.tag. system property regardless of the tag length.

[1] https://cs.android.com/android/platform/superproject/main/+/main:system/logging/logd/README.property;l=50?q=f:readme.property
[2] https://android-review.googlesource.com/c/platform/bionic/+/327226
[3] https://cs.android.com/android/platform/superproject/main/+/main:device/generic/goldfish-opengl/system/codecs/omx/plugin/GoldfishVideoDecoderOMXComponent.cpp;l=20
[4] https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/biometrics/fingerprint/2.2/default/BiometricsFingerprint.cpp;l=16

The currently hard-coded limit is 23 characters. This limit originates
from the pre-Android 7.0 32-character limit on system property names,
because Android's `liblog` allows setting the log level at runtime
through `log.tag` system properties [1]. The limit meant that
"log.tag.SOMETAG" must have been shorter than 32 bytes, leaving 23 bytes
for the tag itself.

The system property length limitation was removed in [2], so since 2017
it no longer applies, and some Android components already use longer
tags [3][4].

This change increases the size of the stack-allocated buffer used for
null-terminating the tag to 128 bytes, and adds support for even longer
tags by falling back to heap-allocated CString when the tag is longer
than that. The fallback path will introduce a performance penalty, but
at the same time will allow manual level adjustment via log.tag. system
property regardless of the tag length.

[1] https://cs.android.com/android/platform/superproject/main/+/main:system/logging/logd/README.property;l=50?q=f:readme.property
[2] https://android-review.googlesource.com/c/platform/bionic/+/327226
[3] https://cs.android.com/android/platform/superproject/main/+/main:device/generic/goldfish-opengl/system/codecs/omx/plugin/GoldfishVideoDecoderOMXComponent.cpp;l=20
[4] https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/biometrics/fingerprint/2.2/default/BiometricsFingerprint.cpp;l=16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant