~ubuntu-branches/ubuntu/jaunty/devil/jaunty

« back to all changes in this revision

Viewing changes to src-IL/src/il_bits.c

  • Committer: Bazaar Package Importer
  • Author(s): Bradley Smith
  • Date: 2009-01-17 15:01:18 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090117150118-4bwb6nmvbz4srsjl
Tags: 1.7.5-4
Actually fix CVE-2008-5262. Closes: #512122.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//-----------------------------------------------------------------------------
2
2
//
3
3
// ImageLib Sources
4
 
// Copyright (C) 2000-2002 by Denton Woods
5
 
// Last modified: 05/25/2001 <--Y2K Compliant! =]
 
4
// Copyright (C) 2000-2008 by Denton Woods
 
5
// Last modified: 08/14/2004
6
6
//
7
7
// Filename: src-IL/src/il_bits.c
8
8
//
118
118
 
119
119
 
120
120
// hehe, "bread".  It reads data into Buffer from the BITFILE, just like fread for FILE.
121
 
ILint bread(ILvoid *Buffer, ILuint Size, ILuint Number, BITFILE *BitFile)
122
 
{
123
 
        //Note that this function is somewhat useless: In binary image
124
 
        //formats, there are some pad bits after each scanline. This
125
 
        //function does not take that into account, so...
 
121
ILint bread(void *Buffer, ILuint Size, ILuint Number, BITFILE *BitFile)
 
122
{
 
123
 
 
124
        //Note that this function is somewhat useless: In binary image
 
125
 
 
126
        //formats, there are some pad bits after each scanline. This
 
127
 
 
128
        //function does not take that into account, so...
 
129
 
126
130
 
127
131
        ILuint  BuffPos = 0, Count = Size * Number;
128
132
 
143
147
}
144
148
 
145
149
 
 
150
// Reads bits and puts the first bit in the file as the highest in the return value.
 
151
ILuint breadVal(ILuint NumBits, BITFILE *BitFile)
 
152
{
 
153
        ILuint  BuffPos = 0;
 
154
        ILuint  Buffer = 0;
 
155
 
 
156
        // Only returning up to 32 bits at one time
 
157
        if (NumBits > 32) {
 
158
                ilSetError(IL_INTERNAL_ERROR);
 
159
                return 0;
 
160
        }
 
161
 
 
162
        while (BuffPos < NumBits) {
 
163
                Buffer <<= 1;
 
164
                if (BitFile->ByteBitOff < 0 || BitFile->ByteBitOff > 7) {
 
165
                        BitFile->ByteBitOff = 7;
 
166
                        if (iread(&BitFile->Buff, 1, 1) != 1)  // Reached eof or error...
 
167
                                return BuffPos;
 
168
                }
 
169
 
 
170
                Buffer = Buffer + (ILubyte)!!(BitFile->Buff & (1 << BitFile->ByteBitOff));
 
171
 
 
172
                BuffPos++;
 
173
                BitFile->ByteBitOff--;
 
174
        }
 
175
 
 
176
        return BuffPos;
 
177
}
 
178
 
 
179
 
146
180
// Not implemented yet.
147
 
/*ILint bwrite(ILvoid *Buffer, ILuint Size, ILuint Number, BITFILE *BitFile)
 
181
/*ILint bwrite(void *Buffer, ILuint Size, ILuint Number, BITFILE *BitFile)
148
182
{
149
183
 
150
184