Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
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
protobuf
Commits
3b70dd78
Commit
3b70dd78
authored
Jun 11, 2011
by
csharptest
Committed by
rogerk
Jun 11, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added recursion limits to AbstractReader.cs
parent
57fa7fdd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
115 additions
and
59 deletions
+115
-59
unittest_extras_xmltest.proto
protos/extest/unittest_extras_xmltest.proto
+55
-51
UnitTestXmlSerializerTestProtoFile.cs
...ers.Test/TestProtos/UnitTestXmlSerializerTestProtoFile.cs
+0
-0
TestWriterFormatJson.cs
src/ProtocolBuffers.Test/TestWriterFormatJson.cs
+9
-0
TestWriterFormatXml.cs
src/ProtocolBuffers.Test/TestWriterFormatXml.cs
+8
-0
AbstractReader.cs
src/ProtocolBuffers/Serialization/AbstractReader.cs
+27
-4
DictionaryWriter.cs
src/ProtocolBuffers/Serialization/DictionaryWriter.cs
+11
-3
XmlFormatReader.cs
src/ProtocolBuffers/Serialization/XmlFormatReader.cs
+5
-1
No files found.
protos/extest/unittest_extras_xmltest.proto
View file @
3b70dd78
// Additional options required for C# generation. File from copyright
// line onwards is as per original distribution.
import
"google/protobuf/csharp_options.proto"
;
option
(
google.protobuf.csharp_file_options
)
.
namespace
=
"Google.ProtocolBuffers.TestProtos"
;
option
(
google.protobuf.csharp_file_options
)
.
umbrella_classname
=
"UnitTestXmlSerializerTestProtoFile"
;
package
protobuf_unittest_extra
;
option
optimize_for
=
SPEED
;
enum
EnumOptions
{
ONE
=
0
;
TWO
=
1
;
THREE
=
2
;
}
message
TestXmlChild
{
repeated
EnumOptions
options
=
3
;
optional
bytes
binary
=
4
;
}
message
TestXmlNoFields
{
}
message
TestXmlMessage
{
optional
int64
number
=
6
;
repeated
int32
numbers
=
2
;
optional
string
text
=
3
;
repeated
string
textlines
=
700
;
optional
bool
valid
=
5
;
optional
TestXmlChild
child
=
1
;
repeated
group
Children
=
401
{
repeated
EnumOptions
options
=
3
;
// Additional options required for C# generation. File from copyright
// line onwards is as per original distribution.
import
"google/protobuf/csharp_options.proto"
;
option
(
google.protobuf.csharp_file_options
)
.
namespace
=
"Google.ProtocolBuffers.TestProtos"
;
option
(
google.protobuf.csharp_file_options
)
.
umbrella_classname
=
"UnitTestXmlSerializerTestProtoFile"
;
package
protobuf_unittest_extra
;
option
optimize_for
=
SPEED
;
enum
EnumOptions
{
ONE
=
0
;
TWO
=
1
;
THREE
=
2
;
}
message
TestXmlChild
{
repeated
EnumOptions
options
=
3
;
optional
bytes
binary
=
4
;
}
message
TestXmlNoFields
{
}
message
TestXmlRescursive
{
optional
TestXmlRescursive
child
=
1
;
}
message
TestXmlMessage
{
optional
int64
number
=
6
;
repeated
int32
numbers
=
2
;
optional
string
text
=
3
;
repeated
string
textlines
=
700
;
optional
bool
valid
=
5
;
optional
TestXmlChild
child
=
1
;
repeated
group
Children
=
401
{
repeated
EnumOptions
options
=
3
;
optional
bytes
binary
=
4
;
}
extensions
100
to
199
;
}
message
TestXmlExtension
{
required
int32
number
=
1
;
}
extend
TestXmlMessage
{
optional
EnumOptions
extension_enum
=
101
;
optional
string
extension_text
=
102
;
repeated
int32
extension_number
=
103
[
packed
=
true
];
optional
TestXmlExtension
extension_message
=
199
;
}
extensions
100
to
199
;
}
message
TestXmlExtension
{
required
int32
number
=
1
;
}
extend
TestXmlMessage
{
optional
EnumOptions
extension_enum
=
101
;
optional
string
extension_text
=
102
;
repeated
int32
extension_number
=
103
[
packed
=
true
];
optional
TestXmlExtension
extension_message
=
199
;
}
src/ProtocolBuffers.Test/TestProtos/UnitTestXmlSerializerTestProtoFile.cs
View file @
3b70dd78
This diff is collapsed.
Click to expand it.
src/ProtocolBuffers.Test/TestWriterFormatJson.cs
View file @
3b70dd78
using
System
;
using
System.IO
;
using
System.Text
;
using
Google.ProtocolBuffers.Serialization
;
using
NUnit.Framework
;
using
Google.ProtocolBuffers.TestProtos
;
...
...
@@ -336,6 +337,14 @@ namespace Google.ProtocolBuffers
Assert
.
AreEqual
(
3
,
ordinal
);
Assert
.
AreEqual
(
3
,
builder
.
TextlinesCount
);
}
[
Test
,
ExpectedException
(
typeof
(
InvalidProtocolBufferException
))]
public
void
TestRecursiveLimit
()
{
StringBuilder
sb
=
new
StringBuilder
(
8192
);
for
(
int
i
=
0
;
i
<
80
;
i
++)
sb
.
Append
(
"{\"child\":"
);
TestXmlRescursive
msg
=
TestXmlRescursive
.
ParseFromJson
(
sb
.
ToString
());
}
[
Test
,
ExpectedException
(
typeof
(
FormatException
))]
public
void
FailWithEmptyText
()
{
...
...
src/ProtocolBuffers.Test/TestWriterFormatXml.cs
View file @
3b70dd78
...
...
@@ -324,5 +324,13 @@ namespace Google.ProtocolBuffers
TestXmlMessage
copy
=
rdr
.
Merge
(
TestXmlMessage
.
CreateBuilder
(),
registry
).
Build
();
Assert
.
AreEqual
(
message
,
copy
);
}
[
Test
,
ExpectedException
(
typeof
(
InvalidProtocolBufferException
))]
public
void
TestRecursiveLimit
()
{
StringBuilder
sb
=
new
StringBuilder
(
8192
);
for
(
int
i
=
0
;
i
<
80
;
i
++)
sb
.
Append
(
"<child>"
);
TestXmlRescursive
msg
=
TestXmlRescursive
.
ParseFromXml
(
"child"
,
XmlReader
.
Create
(
new
StringReader
(
sb
.
ToString
())));
}
}
}
src/ProtocolBuffers/Serialization/AbstractReader.cs
View file @
3b70dd78
...
...
@@ -12,6 +12,9 @@ namespace Google.ProtocolBuffers.Serialization
/// </summary>
public
abstract
class
AbstractReader
:
ICodedInputStream
{
const
int
MaxDepth
=
CodedInputStream
.
DefaultRecursionLimit
;
protected
int
_depth
;
/// <summary>
/// Merges the contents of stream into the provided message builder
/// </summary>
...
...
@@ -330,13 +333,23 @@ namespace Google.ProtocolBuffers.Serialization
{
return
Read
(
ref
value
);
}
void
ICodedInputStream
.
ReadGroup
(
int
fieldNumber
,
IBuilderLite
builder
,
ExtensionRegistry
extensionRegistry
)
{
ReadGroup
(
builder
,
extensionRegistry
);
}
{
if
(
_depth
++
>
MaxDepth
)
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
ReadGroup
(
builder
,
extensionRegistry
);
_depth
--;
}
void
ICodedInputStream
.
ReadUnknownGroup
(
int
fieldNumber
,
IBuilderLite
builder
)
{
throw
new
NotSupportedException
();
}
void
ICodedInputStream
.
ReadMessage
(
IBuilderLite
builder
,
ExtensionRegistry
extensionRegistry
)
{
ReadMessage
(
builder
,
extensionRegistry
);
}
{
if
(
_depth
++
>
MaxDepth
)
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
ReadMessage
(
builder
,
extensionRegistry
);
_depth
--;
}
bool
ICodedInputStream
.
ReadBytes
(
ref
ByteString
value
)
{
return
Read
(
ref
value
);
}
...
...
@@ -439,10 +452,20 @@ namespace Google.ProtocolBuffers.Serialization
}
void
ICodedInputStream
.
ReadMessageArray
<
T
>(
uint
fieldTag
,
string
fieldName
,
ICollection
<
T
>
list
,
T
messageType
,
ExtensionRegistry
registry
)
{
ReadMessageArray
(
fieldName
,
list
,
messageType
,
registry
);
}
{
if
(
_depth
++
>
MaxDepth
)
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
ReadMessageArray
(
fieldName
,
list
,
messageType
,
registry
);
_depth
--;
}
void
ICodedInputStream
.
ReadGroupArray
<
T
>(
uint
fieldTag
,
string
fieldName
,
ICollection
<
T
>
list
,
T
messageType
,
ExtensionRegistry
registry
)
{
ReadGroupArray
(
fieldName
,
list
,
messageType
,
registry
);
}
{
if
(
_depth
++
>
MaxDepth
)
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
ReadGroupArray
(
fieldName
,
list
,
messageType
,
registry
);
_depth
--;
}
bool
ICodedInputStream
.
ReadPrimitiveField
(
FieldType
fieldType
,
ref
object
value
)
{
return
ReadField
(
fieldType
,
ref
value
);
}
...
...
src/ProtocolBuffers/Serialization/DictionaryWriter.cs
View file @
3b70dd78
...
...
@@ -15,7 +15,7 @@ namespace Google.ProtocolBuffers.Serialization
/// Constructs a writer using a new dictionary
/// </summary>
public
DictionaryWriter
()
:
this
(
new
Dictionary
<
string
,
object
>())
:
this
(
new
Dictionary
<
string
,
object
>(
StringComparer
.
Ordinal
))
{
}
/// <summary>
...
...
@@ -27,6 +27,14 @@ namespace Google.ProtocolBuffers.Serialization
_output
=
output
;
}
/// <summary>
/// Creates the dictionary instance for a child message.
/// </summary>
protected
virtual
DictionaryWriter
Create
()
{
return
new
DictionaryWriter
();
}
/// <summary>
/// Accesses the dictionary that is backing this writer
/// </summary>
...
...
@@ -119,7 +127,7 @@ namespace Google.ProtocolBuffers.Serialization
/// </summary>
protected
override
void
WriteMessageOrGroup
(
string
field
,
IMessageLite
message
)
{
DictionaryWriter
writer
=
new
DictionaryWriter
();
DictionaryWriter
writer
=
Create
();
writer
.
WriteMessage
(
message
);
_output
[
field
]
=
writer
.
ToDictionary
();
...
...
@@ -146,7 +154,7 @@ namespace Google.ProtocolBuffers.Serialization
case
FieldType
.
Group
:
case
FieldType
.
Message
:
{
DictionaryWriter
writer
=
new
DictionaryWriter
();
DictionaryWriter
writer
=
Create
();
writer
.
WriteMessage
((
IMessageLite
)
o
);
objects
.
Add
(
writer
.
ToDictionary
());
}
...
...
src/ProtocolBuffers/Serialization/XmlFormatReader.cs
View file @
3b70dd78
...
...
@@ -72,7 +72,11 @@ namespace Google.ProtocolBuffers.Serialization
private
XmlFormatReader
CloneWith
(
XmlReader
rdr
)
{
return
new
XmlFormatReader
(
rdr
).
SetOptions
(
Options
);
XmlFormatReader
copy
=
new
XmlFormatReader
(
rdr
).
SetOptions
(
Options
);
copy
.
_rootElementName
=
_rootElementName
;
copy
.
_depth
=
_depth
;
return
copy
;
}
private
void
NextElement
()
{
...
...
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