~ubuntu-branches/ubuntu/trusty/libwpd/trusty

« back to all changes in this revision

Viewing changes to src/lib/WP3VariableLengthGroup.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2006-07-15 11:58:12 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060715115812-v18efmdayby4clau
Tags: 0.8.6-1
* New upstream release
* swap maintainer/uploader

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libwpd
2
2
 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
3
 
 * Copyright (C) 2004-2005 Fridrich Strba (fridrich.strba@bluewin.ch)
 
3
 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
4
4
 *  
5
5
 * This library is free software; you can redistribute it and/or
6
6
 * modify it under the terms of the GNU Lesser General Public
69
69
        }
70
70
}
71
71
 
 
72
bool WP3VariableLengthGroup::isGroupConsistent(WPXInputStream *input, const uint8_t group)
 
73
{
 
74
        uint32_t startPosition = input->tell();
 
75
 
 
76
        try
 
77
        {
 
78
                uint8_t subGroup = readU8(input);
 
79
                uint16_t size = readU16(input, true);
 
80
 
 
81
                if (input->seek((startPosition + size - 1 - input->tell()), WPX_SEEK_CUR) || input->atEOS())
 
82
                {
 
83
                        input->seek(startPosition, WPX_SEEK_SET);
 
84
                        return false;
 
85
                }
 
86
                if (size != readU16(input, true))
 
87
                {
 
88
                        input->seek(startPosition, WPX_SEEK_SET);
 
89
                        return false;
 
90
                }
 
91
                if (subGroup != readU8(input))
 
92
                {
 
93
                        input->seek(startPosition, WPX_SEEK_SET);
 
94
                        return false;
 
95
                }
 
96
                if (group != readU8(input))
 
97
                {
 
98
                        input->seek(startPosition, WPX_SEEK_SET);
 
99
                        return false;
 
100
                }
 
101
                
 
102
                input->seek(startPosition, WPX_SEEK_SET);
 
103
                return true;
 
104
        }
 
105
        catch(...)
 
106
        {
 
107
                input->seek(startPosition, WPX_SEEK_SET);
 
108
                return false;
 
109
        }
 
110
}
 
111
 
72
112
void WP3VariableLengthGroup::_read(WPXInputStream *input)
73
113
{
74
114
        uint32_t startPosition = input->tell();
82
122
        
83
123
        _readContents(input);
84
124
        
 
125
        input->seek((startPosition + m_size - 5 - input->tell()), WPX_SEEK_CUR);
 
126
 
 
127
        if (m_size != (readU16(input, true) + 4))
 
128
        {
 
129
                WPD_DEBUG_MSG(("WordPerfect: Possible corruption detected. Bailing out!\n"));
 
130
                throw FileException();
 
131
        }
 
132
        if (m_subGroup != readU8(input))
 
133
        {
 
134
                WPD_DEBUG_MSG(("WordPerfect: Possible corruption detected. Bailing out!\n"));
 
135
                throw FileException();
 
136
        }
 
137
        
85
138
        input->seek((startPosition + m_size - 1 - input->tell()), WPX_SEEK_CUR);
86
139
 
87
140
}