/src/libwpd/src/lib/WP5FixedLengthGroup.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | | /* libwpd |
3 | | * Version: MPL 2.0 / LGPLv2.1+ |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * Major Contributor(s): |
10 | | * Copyright (C) 2003 William Lachance (wrlach@gmail.com) |
11 | | * Copyright (C) 2003 Marc Maurer (uwog@uwog.net) |
12 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
13 | | * |
14 | | * For minor contributions see the git repository. |
15 | | * |
16 | | * Alternatively, the contents of this file may be used under the terms |
17 | | * of the GNU Lesser General Public License Version 2.1 or later |
18 | | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
19 | | * applicable instead of those above. |
20 | | * |
21 | | * For further information visit http://libwpd.sourceforge.net |
22 | | */ |
23 | | |
24 | | /* "This product is not manufactured, approved, or supported by |
25 | | * Corel Corporation or Corel Corporation Limited." |
26 | | */ |
27 | | |
28 | | #include "WP5FixedLengthGroup.h" |
29 | | #include "WP5FileStructure.h" |
30 | | #include "WP5AttributeGroup.h" |
31 | | #include "WP5ExtendedCharacterGroup.h" |
32 | | #include "WP5TabGroup.h" |
33 | | #include "WP5IndentGroup.h" |
34 | | #include "WP5UnsupportedFixedLengthGroup.h" |
35 | | #include "libwpd_internal.h" |
36 | | |
37 | | WP5FixedLengthGroup::WP5FixedLengthGroup(const unsigned char groupID): |
38 | 116k | m_group(groupID) |
39 | 116k | { |
40 | 116k | } |
41 | | |
42 | | WP5FixedLengthGroup *WP5FixedLengthGroup::constructFixedLengthGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption, const unsigned char groupID) |
43 | 116k | { |
44 | 116k | switch (groupID) |
45 | 116k | { |
46 | 18.0k | case WP5_TOP_EXTENDED_CHARACTER: |
47 | 18.0k | return new WP5ExtendedCharacterGroup(input, encryption, groupID); |
48 | | |
49 | 40.8k | case WP5_TOP_TAB_GROUP: |
50 | 40.8k | return new WP5TabGroup(input, encryption, groupID); |
51 | | |
52 | 16.4k | case WP5_TOP_INDENT_GROUP: |
53 | 16.4k | return new WP5IndentGroup(input, encryption, groupID); |
54 | | |
55 | 14.3k | case WP5_TOP_ATTRIBUTE_ON: |
56 | 14.3k | return new WP5AttributeOnGroup(input, encryption, groupID); |
57 | | |
58 | 4.87k | case WP5_TOP_ATTRIBUTE_OFF: |
59 | 4.87k | return new WP5AttributeOffGroup(input, encryption, groupID); |
60 | | |
61 | | // Add the remaining cases here |
62 | 21.7k | default: |
63 | 21.7k | return new WP5UnsupportedFixedLengthGroup(input, encryption, groupID); |
64 | 116k | } |
65 | 116k | } |
66 | | |
67 | | bool WP5FixedLengthGroup::isGroupConsistent(librevenge::RVNGInputStream *input, WPXEncryption *encryption, const unsigned char groupID) |
68 | 738k | { |
69 | 738k | long startPosition = input->tell(); |
70 | | |
71 | 738k | try |
72 | 738k | { |
73 | 738k | int size = WP5_FIXED_LENGTH_FUNCTION_GROUP_SIZE[groupID-0xC0]; |
74 | 738k | if (input->seek((startPosition + size - 2), librevenge::RVNG_SEEK_SET) || input->isEnd()) |
75 | 14.4k | { |
76 | 14.4k | input->seek(startPosition, librevenge::RVNG_SEEK_SET); |
77 | 14.4k | return false; |
78 | 14.4k | } |
79 | 724k | if (groupID != readU8(input, encryption)) |
80 | 607k | { |
81 | 607k | input->seek(startPosition, librevenge::RVNG_SEEK_SET); |
82 | 607k | return false; |
83 | 607k | } |
84 | | |
85 | 116k | input->seek(startPosition, librevenge::RVNG_SEEK_SET); |
86 | 116k | return true; |
87 | 724k | } |
88 | 738k | catch (...) |
89 | 738k | { |
90 | 0 | input->seek(startPosition, librevenge::RVNG_SEEK_SET); |
91 | 0 | return false; |
92 | 0 | } |
93 | 738k | } |
94 | | |
95 | | void WP5FixedLengthGroup::_read(librevenge::RVNGInputStream *input, WPXEncryption *encryption) |
96 | 116k | { |
97 | 116k | long startPosition = input->tell(); |
98 | 116k | _readContents(input, encryption); |
99 | | |
100 | 116k | if (m_group >= 0xC0 && m_group <= 0xCF) // just an extra safety check |
101 | 116k | { |
102 | 116k | int size = WP5_FIXED_LENGTH_FUNCTION_GROUP_SIZE[m_group-0xC0]; |
103 | 116k | input->seek((startPosition + size - 2), librevenge::RVNG_SEEK_SET); |
104 | 116k | if (m_group != readU8(input, encryption)) |
105 | 0 | { |
106 | 0 | WPD_DEBUG_MSG(("WordPerfect: Possible corruption detected. Bailing out!\n")); |
107 | 0 | throw FileException(); |
108 | 0 | } |
109 | 116k | } |
110 | 0 | else |
111 | 0 | throw FileException(); |
112 | 116k | } |
113 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |