From 13d91fd6913e238ec54cfe3c498d2c17faa19701 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Wed, 7 Feb 2024 17:00:19 +0400 Subject: [PATCH] fix(YouTube - Litho Filter): Ignore null buffers --- .../patches/components/LithoFilterPatch.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LithoFilterPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LithoFilterPatch.java index f98a5bb244..c992a59032 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LithoFilterPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LithoFilterPatch.java @@ -503,12 +503,16 @@ private static void filterUsingCallbacks(StringTrieSearch pathSearchTree, * Injection point. Called off the main thread. */ @SuppressWarnings("unused") - public static void setProtoBuffer(@NonNull ByteBuffer protobufBuffer) { + public static void setProtoBuffer(@Nullable ByteBuffer protobufBuffer) { // Set the buffer to a thread local. The buffer will remain in memory, even after the call to #filter completes. // This is intentional, as it appears the buffer can be set once and then filtered multiple times. // The buffer will be cleared from memory after a new buffer is set by the same thread, // or when the calling thread eventually dies. - bufferThreadLocal.set(protobufBuffer); + if (protobufBuffer == null) { + Logger.printDebug(() -> "Ignoring null protobuffer"); + } else { + bufferThreadLocal.set(protobufBuffer); + } } /** @@ -523,15 +527,13 @@ public static boolean filter(@Nullable String lithoIdentifier, @NonNull StringBu 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. + // Potentially the buffer may have been null or never set up until now. + // Use an empty buffer so the litho id/path filters still work correctly. if (protobufBuffer == null) { - Logger.printDebug(() -> "Proto buffer is null"); + Logger.printDebug(() -> "Proto buffer is null, using an empty buffer array"); bufferArray = EMPTY_BYTE_ARRAY; } else if (!protobufBuffer.hasArray()) { - Logger.printDebug(() -> "Proto buffer does not have an array"); + Logger.printDebug(() -> "Proto buffer does not have an array, using an empty buffer array"); bufferArray = EMPTY_BYTE_ARRAY; } else { bufferArray = protobufBuffer.array();