diff --git a/apache-commons-vfs.spec b/apache-commons-vfs.spec index d8079c09290b2638dc69cbdfef09ddc3e29592c5..d360962f88512a7c534cda3635da7dcac26cda92 100644 --- a/apache-commons-vfs.spec +++ b/apache-commons-vfs.spec @@ -4,12 +4,12 @@ Name: apache-commons-vfs Version: 2.1 -Release: 15 +Release: 16 Summary: Commons Virtual File System License: ASL 2.0 -Url: http://commons.apache.org/vfs/ +Url: https://commons.apache.org/proper/commons-vfs/ Source0: https://archive.apache.org/dist/commons/vfs/source/commons-vfs-%{version}-src.tar.gz - +Patch0001: fix-wrong-value-returned-when-read-0xff.patch BuildRequires: maven-local mvn(commons-httpclient:commons-httpclient) mvn(commons-logging:commons-logging) BuildRequires: mvn(commons-net:commons-net) mvn(org.apache.ant:ant) mvn(org.apache.commons:commons-collections4) BuildRequires: mvn(org.apache.commons:commons-compress) mvn(org.apache.commons:commons-parent:pom:) @@ -134,6 +134,9 @@ install -p -m 644 commons-vfs %{buildroot}%{_sysconfdir}/ant.d/commons-vfs %license NOTICE.txt %changelog +* Thu Nov 14 2024 shaojiansong - 2.1-16 +- Fix read return wrong value when reading 0xFF + * Wed Sep 02 2020 chengzihan - 2.1-15 - disable hadoop dependance option. diff --git a/fix-wrong-value-returned-when-read-0xff.patch b/fix-wrong-value-returned-when-read-0xff.patch new file mode 100644 index 0000000000000000000000000000000000000000..72ffd662c1809eeffafb1b8078097cb2ea930cc1 --- /dev/null +++ b/fix-wrong-value-returned-when-read-0xff.patch @@ -0,0 +1,241 @@ +# from upstream pr: https://github.com/apache/commons-vfs/pull/93/ +diff -Naur commons-vfs-2.1/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java commons-vfs-2.1-update/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java +--- commons-vfs-2.1/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java 2016-05-02 05:25:00.000000000 +0800 ++++ commons-vfs-2.1-update/core/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContent.java 2024-11-14 16:41:17.325043412 +0800 +@@ -36,6 +36,8 @@ + private final RandomAccessFile raf; + private final InputStream rafis; + ++ private final static int BYTE_VALUE_MASK = 0xFF; ++ + LocalFileRandomAccessContent(final File localFile, final RandomAccessMode mode) throws FileSystemException + { + super(mode); +@@ -50,7 +52,7 @@ + { + try + { +- return raf.readByte(); ++ return raf.readByte() & BYTE_VALUE_MASK; + } + catch (final EOFException e) + { +diff -Naur commons-vfs-2.1/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileRandomAccessContent.java commons-vfs-2.1-update/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileRandomAccessContent.java +--- commons-vfs-2.1/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileRandomAccessContent.java 2016-05-02 05:25:00.000000000 +0800 ++++ commons-vfs-2.1-update/core/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileRandomAccessContent.java 2024-11-14 16:48:42.193267918 +0800 +@@ -68,6 +68,8 @@ + + private final InputStream rafis; + ++ private final static int BYTE_VALUE_MASK = 0xFF; ++ + /** + * @param file The file to access. + * @param mode The access mode. +@@ -85,7 +87,7 @@ + { + try + { +- return readByte(); ++ return readByte() & BYTE_VALUE_MASK; + } + catch (final EOFException e) + { +@@ -248,7 +250,7 @@ + { + if (filePointer < buf.length) + { +- return buf[filePointer++] & 0xFF; ++ return buf[filePointer++] & BYTE_VALUE_MASK; + } + else + { +@@ -429,12 +431,9 @@ + */ + public static long toLong(final byte[] b) + { +- return ((((long) b[7]) & 0xFF) + ((((long) b[6]) & 0xFF) << 8) +- + ((((long) b[5]) & 0xFF) << 16) +- + ((((long) b[4]) & 0xFF) << 24) +- + ((((long) b[3]) & 0xFF) << 32) +- + ((((long) b[2]) & 0xFF) << 40) +- + ((((long) b[1]) & 0xFF) << 48) + ((((long) b[0]) & 0xFF) << 56)); ++ return ((((long) b[7]) & BYTE_VALUE_MASK) + ((((long) b[6]) & BYTE_VALUE_MASK) << 8) + ((((long) b[5]) & BYTE_VALUE_MASK) << 16) ++ + ((((long) b[4]) & BYTE_VALUE_MASK) << 24) + ((((long) b[3]) & BYTE_VALUE_MASK) << 32) + ((((long) b[2]) & BYTE_VALUE_MASK) << 40) ++ + ((((long) b[1]) & BYTE_VALUE_MASK) << 48) + ((((long) b[0]) & BYTE_VALUE_MASK) << 56)); + } + + /** +@@ -483,7 +482,7 @@ + */ + public static int toUnsignedShort(final byte[] b) + { +- return ((b[1] & 0xFF) + ((b[0] & 0xFF) << 8)); ++ return ((b[1] & BYTE_VALUE_MASK) + ((b[0] & BYTE_VALUE_MASK) << 8)); + } + + /* +@@ -528,8 +527,8 @@ + @Override + public void writeChar(final int v) throws IOException + { +- buffer2[0] = (byte) ((v >>> 8) & 0xFF); +- buffer2[1] = (byte) ((v >>> 0) & 0xFF); ++ buffer2[0] = (byte) ((v >>> 8) & BYTE_VALUE_MASK); ++ buffer2[1] = (byte) ((v >>> 0) & BYTE_VALUE_MASK); + write(buffer2); + } + +@@ -578,10 +577,10 @@ + @Override + public void writeInt(final int v) throws IOException + { +- buffer4[0] = (byte) ((v >>> 24) & 0xFF); +- buffer4[1] = (byte) ((v >>> 16) & 0xFF); +- buffer4[2] = (byte) ((v >>> 8) & 0xFF); +- buffer4[3] = (byte) (v & 0xFF); ++ buffer4[0] = (byte) ((v >>> 24) & BYTE_VALUE_MASK); ++ buffer4[1] = (byte) ((v >>> 16) & BYTE_VALUE_MASK); ++ buffer4[2] = (byte) ((v >>> 8) & BYTE_VALUE_MASK); ++ buffer4[3] = (byte) (v & BYTE_VALUE_MASK); + write(buffer4); + } + +@@ -604,8 +603,8 @@ + @Override + public void writeShort(final int v) throws IOException + { +- buffer2[0] = (byte) ((v >>> 8) & 0xFF); +- buffer2[1] = (byte) (v & 0xFF); ++ buffer2[0] = (byte) ((v >>> 8) & BYTE_VALUE_MASK); ++ buffer2[1] = (byte) (v & BYTE_VALUE_MASK); + write(buffer2); + } + +diff -Naur commons-vfs-2.1/core/src/test/java/org/apache/commons/vfs2/provider/local/test/LocalFileRandomAccessContentTestCase.java commons-vfs-2.1-update/core/src/test/java/org/apache/commons/vfs2/provider/local/test/LocalFileRandomAccessContentTestCase.java +--- commons-vfs-2.1/core/src/test/java/org/apache/commons/vfs2/provider/local/test/LocalFileRandomAccessContentTestCase.java 1970-01-01 08:00:00.000000000 +0800 ++++ commons-vfs-2.1-update/core/src/test/java/org/apache/commons/vfs2/provider/local/test/LocalFileRandomAccessContentTestCase.java 2024-11-14 17:13:42.036537949 +0800 +@@ -0,0 +1,53 @@ ++/* ++ * Licensed to the Apache Software Foundation (ASF) under one or more ++ * contributor license agreements. See the NOTICE file distributed with ++ * this work for additional information regarding copyright ownership. ++ * The ASF licenses this file to You 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 org.apache.commons.vfs2.provider.local; ++ ++import org.apache.commons.vfs2.util.RandomAccessMode; ++import org.junit.Assert; ++import org.junit.Test; ++ ++import java.io.File; ++import java.io.IOException; ++import java.io.InputStream; ++ ++/** ++ * @since 2.7.0 ++ */ ++public class LocalFileRandomAccessContentTestCase { ++ ++ private final int EOF = -1; ++ ++ /** ++ * test LocalFileRandomAccessContent InputStream read one byte 0xff; see VFS-624 ++ **/ ++ @Test ++ public void testInputStreamRead0xff() throws IOException { ++ // open test file,this file has only one byte data 0xff ++ File file = new File("src/test/resources/test-data/0xff_file.txt"); ++ ++ // read test data,first data should be 0xFF instead of -1. Will read -1 finally (EOF) ++ try (InputStream in = new LocalFileRandomAccessContent(file, RandomAccessMode.READ).getInputStream()) { ++ // read first data ++ int read = in.read(); ++ Assert.assertNotEquals(EOF, read); ++ Assert.assertEquals(0xFF, read); ++ ++ // read EOF ++ Assert.assertEquals(EOF, in.read()); ++ } ++ } ++} +diff -Naur commons-vfs-2.1/core/src/test/java/org/apache/commons/vfs2/provider/ram/test/RamFileRandomAccessContentTestCase.java commons-vfs-2.1-update/core/src/test/java/org/apache/commons/vfs2/provider/ram/test/RamFileRandomAccessContentTestCase.java +--- commons-vfs-2.1/core/src/test/java/org/apache/commons/vfs2/provider/ram/test/RamFileRandomAccessContentTestCase.java 1970-01-01 08:00:00.000000000 +0800 ++++ commons-vfs-2.1-update/core/src/test/java/org/apache/commons/vfs2/provider/ram/test/RamFileRandomAccessContentTestCase.java 2024-11-14 17:13:51.048665754 +0800 +@@ -0,0 +1,61 @@ ++/* ++ * Licensed to the Apache Software Foundation (ASF) under one or more ++ * contributor license agreements. See the NOTICE file distributed with ++ * this work for additional information regarding copyright ownership. ++ * The ASF licenses this file to You 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 org.apache.commons.vfs2.provider.ram.test; ++ ++import org.apache.commons.vfs2.FileObject; ++import org.apache.commons.vfs2.VFS; ++import org.apache.commons.vfs2.provider.ram.RamFileObject; ++import org.apache.commons.vfs2.provider.ram.RamFileRandomAccessContent; ++import org.apache.commons.vfs2.util.RandomAccessMode; ++import org.junit.Assert; ++import org.junit.Test; ++ ++import java.io.IOException; ++import java.io.InputStream; ++import java.io.OutputStream; ++ ++/** ++ * @since 2.7.0 ++ */ ++public class RamFileRandomAccessContentTestCase { ++ ++ private final int EOF = -1; ++ ++ @Test ++ public void testInputStreamRead0xff() throws IOException { ++ ++ // create ram file to test ++ final FileObject file = VFS.getManager().resolveFile("ram://file"); ++ file.createFile(); ++ ++ // write test data,a single byte 0xFF ++ try (OutputStream out = file.getContent().getOutputStream()) { ++ out.write(0xFF); ++ } ++ ++ // read test data,first data should be 0xFF instead of -1. Will read -1 finally (EOF) ++ try (InputStream in = new RamFileRandomAccessContent((RamFileObject) file, RandomAccessMode.READ).getInputStream()) { ++ // read first data ++ int read = in.read(); ++ Assert.assertNotEquals(EOF, read); ++ Assert.assertEquals(0xFF, read); ++ ++ // read EOF ++ Assert.assertEquals(EOF, in.read()); ++ } ++ } ++} +diff -Naur commons-vfs-2.1/core/src/test/resources/test-data/0xff_file.txt commons-vfs-2.1-update/core/src/test/resources/test-data/0xff_file.txt +--- commons-vfs-2.1/core/src/test/resources/test-data/0xff_file.txt 1970-01-01 08:00:00.000000000 +0800 ++++ commons-vfs-2.1-update/core/src/test/resources/test-data/0xff_file.txt 2024-11-14 16:53:52.922674525 +0800 +@@ -0,0 +1 @@ ++ÿ