guava/CVE-2023-2976-pre.patch
2023-07-04 20:07:28 +08:00

187 lines
6.7 KiB
Diff

From 364aed58e083e305f3f9ffc5bcacf9536f2472ab Mon Sep 17 00:00:00 2001
From: cpovirk <cpovirk@google.com>
Date: Tue, 25 Apr 2023 10:00:41 -0700
Subject: [PATCH] Split the tests for `Files.createTempDir` into a separate
file.
This makes it easier to run them a second time under a newer Android emulator in our internal tests.
RELNOTES=n/a
PiperOrigin-RevId: 526998248
Origin: https://github.com/google/guava/commit/364aed58e083e305f3f9ffc5bcacf9536f2472ab
---
.../common/io/FilesCreateTempDirTest.java | 37 +++++++++++++++++
.../test/com/google/common/io/FilesTest.java | 15 +++----
.../common/annotations/J2ktIncompatible.java | 31 ++++++++++++++
.../io/ElementTypesAreNonnullByDefault.java | 41 +++++++++++++++++++
4 files changed, 115 insertions(+), 9 deletions(-)
create mode 100644 guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java
create mode 100644 guava/src/com/google/common/annotations/J2ktIncompatible.java
create mode 100644 guava/src/com/google/common/io/ElementTypesAreNonnullByDefault.java
diff --git a/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java b/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java
new file mode 100644
index 0000000..557689e
--- /dev/null
+++ b/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2007 The Guava Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.common.io;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.File;
+
+/**
+ * Unit test for {@link Files#createTempDir}.
+ *
+ * @author Chris Nokleberg
+ */
+
+public class FilesCreateTempDirTest extends IoTestCase {
+ public void testCreateTempDir() {
+ File temp = Files.createTempDir();
+ assertTrue(temp.exists());
+ assertTrue(temp.isDirectory());
+ assertThat(temp.listFiles()).isEmpty();
+ assertTrue(temp.delete());
+ }
+}
diff --git a/guava-tests/test/com/google/common/io/FilesTest.java b/guava-tests/test/com/google/common/io/FilesTest.java
index e987f60..d552e0f 100644
--- a/guava-tests/test/com/google/common/io/FilesTest.java
+++ b/guava-tests/test/com/google/common/io/FilesTest.java
@@ -43,7 +43,12 @@ import junit.framework.TestSuite;
/**
* Unit test for {@link Files}.
*
- * <p>Note: {@link Files#fileTraverser()} is tested in {@link FilesFileTraverserTest}.
+ * <p>Some methods are tested in separate files:
+ *
+ * <ul>
+ * <li>{@link Files#fileTraverser()} is tested in {@link FilesFileTraverserTest}.
+ * <li>{@link Files#createTempDir()} is tested in {@link FilesCreateTempDirTest}.
+ * </ul>
*
* @author Chris Nokleberg
*/
@@ -358,14 +363,6 @@ public class FilesTest extends IoTestCase {
}
}
- public void testCreateTempDir() {
- File temp = Files.createTempDir();
- assertTrue(temp.exists());
- assertTrue(temp.isDirectory());
- assertThat(temp.listFiles()).isEmpty();
- assertTrue(temp.delete());
- }
-
public void testMove() throws IOException {
File i18nFile = getTestFile("i18n.txt");
File temp1 = createTempFile();
diff --git a/guava/src/com/google/common/annotations/J2ktIncompatible.java b/guava/src/com/google/common/annotations/J2ktIncompatible.java
new file mode 100644
index 0000000..6e28d02
--- /dev/null
+++ b/guava/src/com/google/common/annotations/J2ktIncompatible.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2009 The Guava Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.common.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The presence of this annotation on an API indicates that the method may <em>not</em> be used with
+ * J2kt.
+ *
+ * @since NEXT
+ */
+@Retention(RetentionPolicy.CLASS)
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
+@GwtCompatible
+public @interface J2ktIncompatible {}
diff --git a/guava/src/com/google/common/io/ElementTypesAreNonnullByDefault.java b/guava/src/com/google/common/io/ElementTypesAreNonnullByDefault.java
new file mode 100644
index 0000000..48bc10f
--- /dev/null
+++ b/guava/src/com/google/common/io/ElementTypesAreNonnullByDefault.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2021 The Guava Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.common.io;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import com.google.common.annotations.GwtCompatible;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.annotation.Nonnull;
+import javax.annotation.meta.TypeQualifierDefault;
+
+/**
+ * Marks all "top-level" types as non-null in a way that is recognized by Kotlin. Note that this
+ * unfortunately includes type-variable usages, so we also provide {@link ParametricNullness} to
+ * "undo" it as best we can.
+ */
+@GwtCompatible
+@Retention(RUNTIME)
+@Target(TYPE)
+@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
+@Nonnull
+@interface ElementTypesAreNonnullByDefault {}
--
2.33.0