From: Dominik Stadler Date: Sat, 22 Jan 2022 06:58:51 +0000 (+0000) Subject: Introduce an OldVisioFormatException similar to other file-types X-Git-Tag: REL_5_2_1~176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9a0933b04e9e90ca3e450ed05fdb0318b47de9fa;p=poi.git Introduce an OldVisioFormatException similar to other file-types git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897321 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java index 7eec5d36bb..068bc0172f 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java @@ -14,11 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hdgf.chunks; import java.nio.charset.Charset; +import org.apache.poi.hdgf.exceptions.OldVisioFormatException; import org.apache.poi.util.LittleEndian; /** @@ -47,7 +47,7 @@ public abstract class ChunkHeader { } else { ch = new ChunkHeaderV6(); } - ch.setType((int)LittleEndian.getUInt(data, offset + 0)); + ch.setType((int)LittleEndian.getUInt(data, offset)); ch.setId((int)LittleEndian.getUInt(data, offset + 4)); ch.setUnknown1((int)LittleEndian.getUInt(data, offset + 8)); ch.setLength((int)LittleEndian.getUInt(data, offset + 12)); @@ -58,7 +58,7 @@ public abstract class ChunkHeader { } else if(documentVersion == 5 || documentVersion == 4) { ChunkHeaderV4V5 ch = new ChunkHeaderV4V5(); - ch.setType(LittleEndian.getShort(data, offset + 0)); + ch.setType(LittleEndian.getShort(data, offset)); ch.setId(LittleEndian.getShort(data, offset + 2)); ch.setUnknown2(LittleEndian.getUByte(data, offset + 4)); ch.setUnknown3(LittleEndian.getUByte(data, offset + 5)); @@ -67,7 +67,7 @@ public abstract class ChunkHeader { return ch; } else { - throw new IllegalArgumentException("Visio files with versions below 4 are not supported, yours was " + documentVersion); + throw new OldVisioFormatException("Visio files with versions below 4 are not supported, yours was " + documentVersion); } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/exceptions/OldVisioFormatException.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/exceptions/OldVisioFormatException.java new file mode 100644 index 0000000000..f8cc0ed34d --- /dev/null +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/exceptions/OldVisioFormatException.java @@ -0,0 +1,25 @@ +/* ==================================================================== + 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.poi.hdgf.exceptions; + +import org.apache.poi.OldFileFormatException; + +public class OldVisioFormatException extends OldFileFormatException { + public OldVisioFormatException(String s) { + super(s); + } +} diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerFactory.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerFactory.java index 504e242104..35c475b175 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerFactory.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerFactory.java @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hdgf.pointers; +import org.apache.poi.hdgf.exceptions.OldVisioFormatException; import org.apache.poi.hdgf.streams.PointerContainingStream; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -43,7 +43,7 @@ public final class PointerFactory { Pointer p; if(version >= 6) { p = new PointerV6(); - p.setType(LittleEndian.getInt(data, offset+0)); + p.setType(LittleEndian.getInt(data, offset)); p.setAddress((int)LittleEndian.getUInt(data, offset+4)); p.setOffset((int)LittleEndian.getUInt(data, offset+8)); p.setLength((int)LittleEndian.getUInt(data, offset+12)); @@ -52,7 +52,7 @@ public final class PointerFactory { return p; } else if(version == 5) { p = new PointerV5(); - p.setType(LittleEndian.getShort(data, offset+0)); + p.setType(LittleEndian.getShort(data, offset)); p.setFormat(LittleEndian.getShort(data, offset+2)); p.setAddress((int)LittleEndian.getUInt(data, offset+4)); p.setOffset((int)LittleEndian.getUInt(data, offset+8)); @@ -60,7 +60,7 @@ public final class PointerFactory { return p; } else { - throw new IllegalArgumentException("Visio files with versions below 5 are not supported, yours was " + version); + throw new OldVisioFormatException("Visio files with versions below 5 are not supported, yours was " + version); } }