Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd139c61

Browse files
committed
Fix#3
1 parentaed2b6d commitd139c61

File tree

6 files changed

+131
-40
lines changed

6 files changed

+131
-40
lines changed

‎compoundfiles/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
CompoundFileLargeNormalFatError,
8383
CompoundFileLargeMiniFatError,
8484
CompoundFileMasterLoopError,
85+
CompoundFileNormalLoopError,
8586
CompoundFileWarning,
8687
CompoundFileHeaderWarning,
8788
CompoundFileMasterFatWarning,
@@ -90,6 +91,13 @@
9091
CompoundFileSectorSizeWarning,
9192
CompoundFileMasterSectorWarning,
9293
CompoundFileNormalSectorWarning,
94+
CompoundFileDirEntryWarning,
95+
CompoundFileDirNameWarning,
96+
CompoundFileDirTypeWarning,
97+
CompoundFileDirIndexWarning,
98+
CompoundFileDirTimeWarning,
99+
CompoundFileDirSectorWarning,
100+
CompoundFileDirSizeWarning,
93101
)
94102
fromcompoundfiles.streamsimportCompoundFileStream
95103
fromcompoundfiles.entitiesimportCompoundFileEntity

‎compoundfiles/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
DIR_HEADER=st.Struct(native_str(''.join((
8282
native_str('<'),# little-endian format
8383
native_str('64s'),# NULL-terminated filename in UTF-16 little-endian encoding
84-
native_str('H'),# length of filename (why?!)
84+
native_str('H'),# length of filenamein bytes(why?!)
8585
native_str('B'),# dir-entry type
8686
native_str('B'),# red (0) or black (1) entry
8787
native_str('L'),# ID of left-sibling node

‎compoundfiles/entities.py

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@
3535
importdatetimeasdt
3636
frompprintimportpformat
3737

38-
fromcompoundfiles.errorsimportCompoundFileError,CompoundFileWarning
38+
fromcompoundfiles.errorsimport (
39+
CompoundFileDirEntryWarning,
40+
CompoundFileDirNameWarning,
41+
CompoundFileDirTypeWarning,
42+
CompoundFileDirIndexWarning,
43+
CompoundFileDirTimeWarning,
44+
CompoundFileDirSectorWarning,
45+
CompoundFileDirSizeWarning,
46+
)
3947
fromcompoundfiles.constimport (
4048
NO_STREAM,
4149
DIR_INVALID,
@@ -120,53 +128,88 @@ def __init__(self, parent, stream, index):
120128
try:
121129
self.name=self.name[:self.name.index('\0')]
122130
exceptValueError:
123-
self._check(False,'missing NULL terminator in name')
131+
warnings.warn(
132+
CompoundFileDirNameWarning(
133+
'missing NULL terminator in name'))
124134
self.name=self.name[:name_len]
125135
ifindex==0:
126-
self._check(self._entry_type==DIR_ROOT,'invalid type')
136+
ifself._entry_type!=DIR_ROOT:
137+
warnings.warn(
138+
CompoundFileDirTypeWarning('invalid type'))
127139
self._entry_type=DIR_ROOT
128140
elifnotself._entry_typein (DIR_STREAM,DIR_STORAGE,DIR_INVALID):
129-
self._check(False,'invalid type')
130-
self._entry_type=DIR_INVALID
141+
warnings.warn(
142+
CompoundFileDirTypeWarning('invalid type'))
143+
self._entry_type=DIR_INVALID
131144
ifself._entry_type==DIR_INVALID:
132-
self._check(self.name=='','non-empty name')
133-
self._check(name_len==0,'invalid name length (%d)'%name_len)
134-
self._check(user_flags==0,'non-zero user flags')
145+
ifself.name!='':
146+
warnings.warn(
147+
CompoundFileDirNameWarning('non-empty name'))
148+
ifname_len!=0:
149+
warnings.warn(
150+
CompoundFileDirNameWarning('non-zero name length'))
151+
ifuser_flags!=0:
152+
warnings.warn(
153+
CompoundFileDirEntryWarning('non-zero user flags'))
135154
else:
136155
# Name length is in bytes, including NULL terminator ... for a
137156
# unicode encoded name ... *headdesk*
138-
self._check(
139-
(len(self.name)+1)*2==name_len,
140-
'invalid name length (%d)'%name_len)
157+
if (len(self.name)+1)*2!=name_len:
158+
warnings.warn(
159+
CompoundFileDirNameWarning('invalid name length (%d)'%name_len))
141160
ifself._entry_typein (DIR_INVALID,DIR_ROOT):
142-
self._check(self._left_index==NO_STREAM,'invalid left sibling')
143-
self._check(self._right_index==NO_STREAM,'invalid right sibling')
161+
ifself._left_index!=NO_STREAM:
162+
warnings.warn(
163+
CompoundFileDirIndexWarning('invalid left sibling'))
164+
ifself._right_index!=NO_STREAM:
165+
warnings.warn(
166+
CompoundFileDirIndexWarning('invalid right sibling'))
144167
self._left_index=NO_STREAM
145168
self._right_index=NO_STREAM
146169
ifself._entry_typein (DIR_INVALID,DIR_STREAM):
147-
self._check(self._child_index==NO_STREAM,'invalid child index')
148-
self._check(self.uuid==b'\0'*16,'non-zero UUID')
149-
self._check(created==0,'non-zero creation timestamp')
150-
self._check(modified==0,'non-zero modification timestamp')
170+
ifself._child_index!=NO_STREAM:
171+
warnings.warn(
172+
CompoundFileDirIndexWarning('invalid child index'))
173+
ifself.uuid!=b'\0'*16:
174+
warnings.warn(
175+
CompoundFileDirEntryWarning('non-zero UUID'))
176+
ifcreated!=0:
177+
warnings.warn(
178+
CompoundFileDirTimeWarning('non-zero creation timestamp'))
179+
ifmodified!=0:
180+
warnings.warn(
181+
CompoundFileDirTimeWarning('non-zero modification timestamp'))
151182
self._child_index=NO_STREAM
152183
self.uuid=b'\0'*16
153184
created=0
154185
modified=0
155186
ifself._entry_typein (DIR_INVALID,DIR_STORAGE):
156-
self._check(self._start_sector==0,
157-
'non-zero start sector (%d)'%self._start_sector)
158-
self._check(size_low==0,
159-
'non-zero size low-bits (%d)'%size_low)
160-
self._check(size_high==0,
161-
'non-zero size high-bits (%d)'%size_high)
187+
ifself._start_sector!=0:
188+
warnings.warn(
189+
CompoundFileDirSectorWarning(
190+
'non-zero start sector (%d)'%self._start_sector))
191+
ifsize_low!=0:
192+
warnings.warn(
193+
CompoundFileDirSizeWarning(
194+
'non-zero size low-bits (%d)'%size_low))
195+
ifsize_high!=0:
196+
warnings.warn(
197+
CompoundFileDirSizeWarning(
198+
'non-zero size high-bits (%d)'%size_high))
162199
self._start_sector=0
163200
size_low=0
164201
size_high=0
165202
ifparent._normal_sector_size==512:
166203
# Surely this should be checking DLL version instead of sector
167204
# size?! But the spec does state sector size ...
168-
self._check(size_high==0,'invalid size in small sector file')
169-
self._check(size_low<1<<31,'size too large for small sector file')
205+
ifsize_high!=0:
206+
warnings.warn(
207+
CompoundFileDirSizeWarning(
208+
'invalid size in small sector file'))
209+
ifsize_low>=1<<31:
210+
warnings.warn(
211+
CompoundFileDirSizeWarning(
212+
'size too large for small sector file'))
170213
size_high=0
171214
self.size= (size_high<<32)|size_low
172215
epoch=dt.datetime(1601,1,1)
@@ -185,12 +228,6 @@ def isfile(self):
185228
defisdir(self):
186229
returnself._entry_typein (DIR_STORAGE,DIR_ROOT)
187230

188-
def_check(self,valid,message):
189-
ifnotvalid:
190-
warnings.warn(
191-
CompoundFileWarning(
192-
'%s in dir entry %d'% (message,self._index)))
193-
194231
def_build_tree(self,entries):
195232

196233
# XXX Need cycle detection in here - add a visited flag?
@@ -199,13 +236,15 @@ def walk(node):
199236
try:
200237
walk(entries[node._left_index])
201238
exceptIndexError:
202-
node._check(False,'invalid left index')
239+
warnings.warn(
240+
CompoundFileDirIndexWarning('invalid left index'))
203241
self._children.append(node)
204242
ifnode._right_index!=NO_STREAM:
205243
try:
206244
walk(entries[node._right_index])
207245
exceptIndexError:
208-
node._check(False,'invalid right index')
246+
warnings.warn(
247+
CompoundFileDirIndexWarning('invalid right index'))
209248
node._build_tree(entries)
210249

211250
ifself.isdir:
@@ -214,7 +253,8 @@ def walk(node):
214253
walk(entries[self._child_index])
215254
exceptIndexError:
216255
ifself._child_index!=NO_STREAM:
217-
self._check(False,'invalid child index')
256+
warnings.warn(
257+
CompoundFileDirIndexWarning('invalid child index'))
218258

219259
def__len__(self):
220260
returnlen(self._children)

‎compoundfiles/errors.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ class CompoundFileLargeNormalFatError(CompoundFileNormalFatError):
7676
Error raised when the document has an excessively large FAT.
7777
"""
7878

79+
classCompoundFileNormalLoopError(CompoundFileNormalFatError):
80+
"""
81+
Error raised when a cycle is detected in a FAT chain.
82+
"""
83+
7984
classCompoundFileLargeMiniFatError(CompoundFileMiniFatError):
8085
"""
8186
Error raised when the document has an excessively large mini FAT.
@@ -112,6 +117,11 @@ class CompoundFileMiniFatWarning(CompoundFileWarning):
112117
Base class for warnings about mini FAT issues.
113118
"""
114119

120+
classCompoundFileDirEntryWarning(CompoundFileWarning):
121+
"""
122+
Base class for warnings about directory entry issues.
123+
"""
124+
115125
classCompoundFileSectorSizeWarning(CompoundFileHeaderWarning):
116126
"""
117127
Base class for warnings about strange sector sizes in compound documents.
@@ -126,3 +136,34 @@ class CompoundFileNormalSectorWarning(CompoundFileNormalFatWarning):
126136
"""
127137
Class for warnings about mis-marked normal FAT sectors.
128138
"""
139+
140+
classCompoundFileDirNameWarning(CompoundFileDirEntryWarning):
141+
"""
142+
Class for warnings about invalid directory entry names.
143+
"""
144+
145+
classCompoundFileDirTypeWarning(CompoundFileDirEntryWarning):
146+
"""
147+
Class for warnings about invalid directory entry types.
148+
"""
149+
150+
classCompoundFileDirIndexWarning(CompoundFileDirEntryWarning):
151+
"""
152+
Class for warnings about directory sibling or child indexes.
153+
"""
154+
155+
classCompoundFileDirTimeWarning(CompoundFileDirEntryWarning):
156+
"""
157+
Class for warnings about directory entry timestamps.
158+
"""
159+
160+
classCompoundFileDirSectorWarning(CompoundFileDirEntryWarning):
161+
"""
162+
Class for warnings about directory start sectors.
163+
"""
164+
165+
classCompoundFileDirSizeWarning(CompoundFileDirEntryWarning):
166+
"""
167+
Class for warnings about directory size entries.
168+
"""
169+

‎compoundfiles/reader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
CompoundFileLargeNormalFatError,
4949
CompoundFileLargeMiniFatError,
5050
CompoundFileMasterLoopError,
51-
CompoundFileWarning,
5251
CompoundFileMasterFatWarning,
5352
CompoundFileNormalFatWarning,
5453
CompoundFileMiniFatWarning,

‎compoundfiles/streams.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
fromarrayimportarray
3838
fromabcimportabstractmethod
3939

40-
fromcompoundfiles.errorsimportCompoundFileError,CompoundFileWarning
40+
fromcompoundfiles.errorsimport (
41+
CompoundFileNormalLoopError,
42+
CompoundFileDirSizeWarning,
43+
)
4144
fromcompoundfiles.constimportEND_OF_CHAIN
4245

4346

@@ -71,7 +74,7 @@ def _load_sectors(self, start, fat):
7174
ifhare!=END_OF_CHAIN:
7275
hare=fat[hare]
7376
ifhare==tortoise:
74-
raiseCompoundFileError(
77+
raiseCompoundFileNormalLoopError(
7578
'cyclic FAT chain found starting at %d'%start)
7679

7780
@abstractmethod
@@ -180,7 +183,7 @@ def __init__(self, parent, start, length=None):
180183
self._length=max_length
181184
elifnot (min_length<=length<=max_length):
182185
warnings.warn(
183-
CompoundFileWarning(
186+
CompoundFileDirSizeWarning(
184187
'length (%d) of stream at sector %d exceeds bounds '
185188
'(%d-%d)'% (length,start,min_length,max_length)))
186189
self._length=max_length
@@ -223,7 +226,7 @@ def __init__(self, parent, start, length=None):
223226
max_length=len(self._sectors)*self._sector_size
224227
iflengthisnotNoneandlength>max_length:
225228
warnings.warn(
226-
CompoundFileWarning(
229+
CompoundFileDirSizeWarning(
227230
'length (%d) of stream at sector %d exceeds max'% (
228231
length,start,max_length)))
229232
self._length=min(max_length,lengthormax_length)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp