Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
chore: Merge branch dev to main (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX authored Feb 7, 2024
2 parents 04c10d8 + 1a4c61d commit 9996b2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.3.1-dev.1](https://github.com/ReVanced/revanced-integrations/compare/v1.3.0...v1.3.1-dev.1) (2024-02-07)


### Bug Fixes

* **YouTube - Litho Filter:** Do not show toast if protobuffer is empty or null ([#563](https://github.com/ReVanced/revanced-integrations/issues/563)) ([ea5748c](https://github.com/ReVanced/revanced-integrations/commit/ea5748ca8e0c7130face5ca4c86cfe5e00a3ed65))

# [1.3.0](https://github.com/ReVanced/revanced-integrations/compare/v1.2.1...v1.3.0) (2024-02-05)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,17 @@ private static final class LithoFilterParameters {
final String path;
final byte[] protoBuffer;

LithoFilterParameters(@Nullable String lithoIdentifier, StringBuilder lithoPath, ByteBuffer protoBuffer) {
LithoFilterParameters(@Nullable String lithoIdentifier, String lithoPath, byte[] protoBuffer) {
this.identifier = lithoIdentifier;
this.path = lithoPath.toString();
this.protoBuffer = protoBuffer.array();
this.path = lithoPath;
this.protoBuffer = protoBuffer;
}

@NonNull
@Override
public String toString() {
// Estimate the percentage of the buffer that are Strings.
StringBuilder builder = new StringBuilder(protoBuffer.length / 2);
StringBuilder builder = new StringBuilder(Math.max(100, protoBuffer.length / 2));
builder.append( "ID: ");
builder.append(identifier);
builder.append(" Path: ");
Expand Down Expand Up @@ -457,6 +457,8 @@ private static void findAsciiStrings(StringBuilder builder, byte[] buffer) {
private static final StringTrieSearch pathSearchTree = new StringTrieSearch();
private static final StringTrieSearch identifierSearchTree = new StringTrieSearch();

private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];

/**
* Because litho filtering is multi-threaded and the buffer is passed in from a different injection point,
* the buffer is saved to a ThreadLocal so each calling thread does not interfere with other threads.
Expand Down Expand Up @@ -520,17 +522,23 @@ public static boolean filter(@Nullable String lithoIdentifier, @NonNull StringBu
return false;

ByteBuffer protobufBuffer = bufferThreadLocal.get();
final byte[] bufferArray;
// The buffer can be null or empty when using YT 19.x.
// This is likely caused by different threads setting the buffer and calling this method.
// 100% fixing this would require passing the buffer into this method (which may not be so simple).
// For now, still filter with an empty buffer so the non proto buffer filters work correctly.
if (protobufBuffer == null) {
Logger.printException(() -> "Proto buffer is null"); // Should never happen.
return false;
}

if (!protobufBuffer.hasArray()) {
Logger.printDebug(() -> "Proto buffer is null");
bufferArray = EMPTY_BYTE_ARRAY;
} else if (!protobufBuffer.hasArray()) {
Logger.printDebug(() -> "Proto buffer does not have an array");
return false;
bufferArray = EMPTY_BYTE_ARRAY;
} else {
bufferArray = protobufBuffer.array();
}

LithoFilterParameters parameter = new LithoFilterParameters(lithoIdentifier, pathBuilder, protobufBuffer);
LithoFilterParameters parameter = new LithoFilterParameters(lithoIdentifier,
pathBuilder.toString(), bufferArray);
Logger.printDebug(() -> "Searching " + parameter);

if (parameter.identifier != null) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.parallel = true
org.gradle.caching = true
android.useAndroidX = true
version = 1.3.0
version = 1.3.1-dev.1

0 comments on commit 9996b2d

Please sign in to comment.