~ubuntu-branches/ubuntu/wily/libwpd/wily-proposed

« back to all changes in this revision

Viewing changes to src/lib/WP1Heuristics.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2014-08-08 00:35:26 UTC
  • mfrom: (11.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20140808003526-7pku3062w50cnsod
Tags: 0.10.0-2
* upload to unstable

* fix debian/copyright for MPL-2.0 | LGPL-2.1+ dual-license 

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "libwpd_internal.h"
31
31
#include <limits>
32
32
 
33
 
WPDPasswordMatch WP1Heuristics::verifyPassword(WPXInputStream *input, const char *password)
 
33
using namespace libwpd;
 
34
 
 
35
WPDPasswordMatch WP1Heuristics::verifyPassword(librevenge::RVNGInputStream *input, const char *password)
34
36
{
35
37
        if (!password)
36
38
                return WPD_PASSWORD_MATCH_DONTKNOW;
37
39
 
38
 
        input->seek(0, WPX_SEEK_SET);
 
40
        input->seek(0, librevenge::RVNG_SEEK_SET);
39
41
        WPXEncryption *encryption = 0;
40
42
        try
41
43
        {
65
67
        }
66
68
}
67
69
 
68
 
WPDConfidence WP1Heuristics::isWP1FileFormat(WPXInputStream *input, const char *password)
 
70
WPDConfidence WP1Heuristics::isWP1FileFormat(librevenge::RVNGInputStream *input, const char *password)
69
71
{
70
 
        input->seek(0, WPX_SEEK_SET);
 
72
        input->seek(0, librevenge::RVNG_SEEK_SET);
71
73
        WPXEncryption *encryption = 0;
72
74
 
73
75
        try
91
93
                        }
92
94
                }
93
95
 
94
 
                input->seek(0, WPX_SEEK_SET);
 
96
                input->seek(0, librevenge::RVNG_SEEK_SET);
95
97
                if (password && encryption)
96
 
                        input->seek(6, WPX_SEEK_SET);
 
98
                        input->seek(6, librevenge::RVNG_SEEK_SET);
97
99
 
98
100
                int functionGroupCount = 0;
99
101
 
100
102
                WPD_DEBUG_MSG(("WP1Heuristics::isWP1FileFormat()\n"));
101
103
 
102
 
                while (!input->atEOS())
 
104
                while (!input->isEnd())
103
105
                {
104
 
                        uint8_t readVal = readU8(input, encryption);
 
106
                        unsigned char readVal = readU8(input, encryption);
105
107
 
106
108
                        WPD_DEBUG_MSG(("WP1Heuristics, Offset 0x%.8x, value 0x%.2x (%c)\n", (unsigned int)input->tell() - 1, readVal, readVal));
107
109
 
108
 
                        if (readVal < (uint8_t)0x20)
 
110
                        if (readVal < (unsigned char)0x20)
109
111
                        {
110
112
                                // line breaks et al, skip
111
113
                        }
112
 
                        else if (readVal >= (uint8_t)0x20 && readVal <= (uint8_t)0x7F)
 
114
                        else if (readVal >= (unsigned char)0x20 && readVal <= (unsigned char)0x7F)
113
115
                        {
114
116
                                // normal ASCII characters, skip
115
117
                        }
116
 
                        else if (readVal >= (uint8_t)0x80 && readVal <= (uint8_t)0xBF)
 
118
                        else if (readVal >= (unsigned char)0x80 && readVal <= (unsigned char)0xBF)
117
119
                        {
118
120
                                // single character function codes, skip
119
121
                                functionGroupCount++;
120
122
                        }
121
 
                        else if (readVal >= (uint8_t)0xFF)
 
123
                        else if (readVal >= (unsigned char)0xFF)
122
124
                        {
123
125
                                if (encryption)
124
126
                                        delete encryption;
140
142
                                        //   that we observed in variable length WP1 functions
141
143
 
142
144
                                        unsigned functionLength = readU32(input, encryption, true);
143
 
                                        if (functionLength > ((std::numeric_limits<uint32_t>::max)() / 2))
 
145
                                        if (functionLength > ((std::numeric_limits<unsigned>::max)() / 2))
144
146
                                        {
145
147
                                                if (encryption)
146
148
                                                        delete encryption;
154
156
                                        }
155
157
                                        WPD_DEBUG_MSG(("WP1Heuristics functionLength = 0x%.8x\n", (unsigned int)functionLength));
156
158
 
157
 
                                        input->seek(functionLength, WPX_SEEK_CUR);
 
159
                                        input->seek(functionLength, librevenge::RVNG_SEEK_CUR);
158
160
                                        unsigned long closingFunctionLength = readU32(input, encryption, true);
159
161
                                        WPD_DEBUG_MSG(("WP1Heuristics closingFunctionLength = 0x%.8x\n", (unsigned int)closingFunctionLength));
160
162
                                        if (functionLength != closingFunctionLength)
164
166
                                                return WPD_CONFIDENCE_NONE;
165
167
                                        }
166
168
 
167
 
                                        uint8_t closingGate = 0;
168
 
                                        if (!input->atEOS())
 
169
                                        unsigned char closingGate = 0;
 
170
                                        if (!input->isEnd())
169
171
                                        {
170
172
                                                closingGate = readU8(input, encryption);
171
173
                                                WPD_DEBUG_MSG(("WP1Heuristics closingGate = 0x%.2x\n", closingGate));
178
180
                                        }
179
181
 
180
182
                                        // when passed the complete file, we don't allow for open groups when we've reached EOF
181
 
                                        if (input->atEOS() && (closingGate != readVal))
 
183
                                        if (input->isEnd() && (closingGate != readVal))
182
184
                                        {
183
185
                                                if (encryption)
184
186
                                                        delete encryption;
192
194
                                        // fixed length function group
193
195
 
194
196
                                        // seek to the position where the closing gate should be
195
 
                                        int res = input->seek(WP1_FUNCTION_GROUP_SIZE[readVal-0xC0]-2, WPX_SEEK_CUR);
 
197
                                        int res = input->seek(WP1_FUNCTION_GROUP_SIZE[readVal-0xC0]-2, librevenge::RVNG_SEEK_CUR);
196
198
                                        // when passed the complete file, we should be able to do that
197
199
                                        if (res)
198
200
                                        {
202
204
                                        }
203
205
 
204
206
                                        // read the closing gate
205
 
                                        uint8_t readNextVal = readU8(input, encryption);
 
207
                                        unsigned char readNextVal = readU8(input, encryption);
206
208
                                        if (readNextVal != readVal)
207
209
                                        {
208
210
                                                if (encryption)