Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
9689d38b
Commit
9689d38b
authored
Aug 19, 2015
by
Robert
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #235 from FrankStain/master
2Gb buffer size checks fixed for Python Builder
parents
d06b2736
33e4ab65
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
builder.py
python/flatbuffers/builder.py
+10
-3
No files found.
python/flatbuffers/builder.py
View file @
9689d38b
...
...
@@ -87,13 +87,20 @@ class Builder(object):
__slots__
=
(
"Bytes"
,
"current_vtable"
,
"head"
,
"minalign"
,
"objectEnd"
,
"vtables"
)
"""
Maximum buffer size constant, in bytes.
Builder will never allow it's buffer grow over this size.
Currently equals 2Gb.
"""
MAX_BUFFER_SIZE
=
2
**
31
def
__init__
(
self
,
initialSize
):
"""
Initializes a Builder of size `initial_size`.
The internal buffer is grown as needed.
"""
if
not
(
0
<=
initialSize
<
(
2
**
UOffsetTFlags
.
bytewidth
-
1
)
):
if
not
(
0
<=
initialSize
<
=
Builder
.
MAX_BUFFER_SIZE
):
msg
=
"flatbuffers: Cannot create Builder larger than 2 gigabytes."
raise
BuilderSizeError
(
msg
)
...
...
@@ -238,11 +245,11 @@ class Builder(object):
def
growByteBuffer
(
self
):
"""Doubles the size of the byteslice, and copies the old data towards
the end of the new buffer (since we build the buffer backwards)."""
if
not
len
(
self
.
Bytes
)
<=
2
**
20
:
if
len
(
self
.
Bytes
)
==
Builder
.
MAX_BUFFER_SIZE
:
msg
=
"flatbuffers: cannot grow buffer beyond 2 gigabytes"
raise
BuilderSizeError
(
msg
)
newSize
=
len
(
self
.
Bytes
)
*
2
newSize
=
min
(
len
(
self
.
Bytes
)
*
2
,
Builder
.
MAX_BUFFER_SIZE
)
if
newSize
==
0
:
newSize
=
1
bytes2
=
bytearray
(
newSize
)
...
...
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