Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
79e00f69
Commit
79e00f69
authored
Oct 06, 2016
by
ElenaSubbotina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug #33183
parent
cbf3fcf2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
19 deletions
+50
-19
Common/OfficeFileFormatChecker.h
Common/OfficeFileFormatChecker.h
+1
-1
Common/OfficeFileFormatChecker2.cpp
Common/OfficeFileFormatChecker2.cpp
+49
-18
No files found.
Common/OfficeFileFormatChecker.h
View file @
79e00f69
...
...
@@ -72,7 +72,7 @@ private:
bool
isMS_OFFCRYPTOFormatFile
(
POLE
::
Storage
*
storage
);
bool
isRtfFormatFile
(
unsigned
char
*
pBuffer
,
int
dwBytes
);
bool
isHtmlFormatFile
(
unsigned
char
*
pBuffer
,
int
dwBytes
);
bool
isHtmlFormatFile
(
unsigned
char
*
pBuffer
,
int
dwBytes
,
bool
testCloseTag
);
bool
isPdfFormatFile
(
unsigned
char
*
pBuffer
,
int
dwBytes
);
bool
isBinaryDoctFormatFile
(
unsigned
char
*
pBuffer
,
int
dwBytes
);
...
...
Common/OfficeFileFormatChecker2.cpp
View file @
79e00f69
...
...
@@ -29,11 +29,13 @@
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <algorithm>
#include "OfficeFileFormatChecker.h"
#include "../DesktopEditor/common/File.h"
#include "../OfficeUtils/src/OfficeUtils.h"
#include "3dParty/pole/pole.h"
#include <algorithm>
#define MIN_SIZE_BUFFER 4096
#define MAX_SIZE_BUFFER 102400
...
...
@@ -47,22 +49,40 @@ bool COfficeFileFormatChecker::isRtfFormatFile(unsigned char* pBuffer,int dwByte
return
false
;
}
bool
COfficeFileFormatChecker
::
isHtmlFormatFile
(
unsigned
char
*
pBuffer
,
int
dwBytes
)
bool
COfficeFileFormatChecker
::
isHtmlFormatFile
(
unsigned
char
*
pBuffer
,
int
dwBytes
,
bool
testCloseTag
)
{
if
(
pBuffer
==
NULL
)
return
false
;
bool
tagOpen
=
false
;
//Html File is XML-file with rootElement - html
for
(
int
i
=
0
;
i
<
dwBytes
-
4
&&
i
<
100
;
i
++
)
{
if
(
0x3C
==
pBuffer
[
i
])
tagOpen
=
true
;
else
if
(
0x3E
==
pBuffer
[
i
])
tagOpen
=
false
;
else
if
(
tagOpen
&&
(
0x48
==
pBuffer
[
i
]
||
0x68
==
pBuffer
[
i
])
&&
(
0x54
==
pBuffer
[
i
+
1
]
||
0x74
==
pBuffer
[
i
+
1
])
&&
(
0x4d
==
pBuffer
[
i
+
2
]
||
0x6d
==
pBuffer
[
i
+
2
])
&&
(
0x4c
==
pBuffer
[
i
+
3
]
||
0x6c
==
pBuffer
[
i
+
3
]))
return
true
;
}
bool
tagOpen
=
false
;
if
(
testCloseTag
)
{
for
(
int
i
=
0
;
i
<
dwBytes
-
6
;
i
++
)
{
if
((
0x3C
==
pBuffer
[
i
])
&&
(
0x2F
==
pBuffer
[
i
+
1
])
&&
(
0x48
==
pBuffer
[
i
+
2
]
||
0x68
==
pBuffer
[
i
+
2
])
&&
(
0x54
==
pBuffer
[
i
+
3
]
||
0x74
==
pBuffer
[
i
+
3
])
&&
(
0x4d
==
pBuffer
[
i
+
4
]
||
0x6d
==
pBuffer
[
i
+
4
])
&&
(
0x4c
==
pBuffer
[
i
+
5
]
||
0x6c
==
pBuffer
[
i
+
5
]))
{
return
true
;
}
}
}
else
{
for
(
int
i
=
0
;
i
<
dwBytes
-
4
&&
i
<
100
;
i
++
)
{
if
(
0x3C
==
pBuffer
[
i
])
tagOpen
=
true
;
else
if
(
0x3E
==
pBuffer
[
i
])
tagOpen
=
false
;
else
if
(
tagOpen
&&
(
0x48
==
pBuffer
[
i
]
||
0x68
==
pBuffer
[
i
])
&&
(
0x54
==
pBuffer
[
i
+
1
]
||
0x74
==
pBuffer
[
i
+
1
])
&&
(
0x4d
==
pBuffer
[
i
+
2
]
||
0x6d
==
pBuffer
[
i
+
2
])
&&
(
0x4c
==
pBuffer
[
i
+
3
]
||
0x6c
==
pBuffer
[
i
+
3
]))
{
return
true
;
}
}
}
return
false
;
}
...
...
@@ -222,9 +242,8 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring & fileName)
if
(
!
buffer
){
file
.
CloseFile
();
return
false
;}
DWORD
dwReadBytes
=
0
;
file
.
ReadFile
(
buffer
,
MIN_SIZE_BUFFER
,
dwReadBytes
);
file
.
ReadFile
(
buffer
,
MIN_SIZE_BUFFER
,
dwReadBytes
);
int
sizeRead
=
(
int
)
dwReadBytes
;
file
.
CloseFile
();
if
(
isRtfFormatFile
(
buffer
,
sizeRead
)
)
{
...
...
@@ -250,15 +269,27 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring & fileName)
{
nFileType
=
AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_DJVU
;
}
else
if
(
isHtmlFormatFile
(
buffer
,
sizeRead
)
)
else
if
(
isHtmlFormatFile
(
buffer
,
sizeRead
,
false
)
)
{
nFileType
=
AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML
;
long
fileSize
=
file
.
GetFileSize
();
if
(
fileSize
>
MIN_SIZE_BUFFER
)
{
file
.
SeekFile
(
fileSize
-
MIN_SIZE_BUFFER
);
file
.
ReadFile
(
buffer
,
MIN_SIZE_BUFFER
,
dwReadBytes
);
int
sizeRead
=
(
int
)
dwReadBytes
;
}
if
(
isHtmlFormatFile
(
buffer
,
sizeRead
,
true
))
{
nFileType
=
AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML
;
}
}
else
if
(
isFB2FormatFile
(
buffer
,
sizeRead
)
)
{
nFileType
=
AVS_OFFICESTUDIO_FILE_DOCUMENT_FB2
;
}
/////////////////////////////////////////////////////////////////////////
file
.
CloseFile
();
if
(
buffer
)
delete
[]
buffer
;
buffer
=
NULL
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment