summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/JavaUtil.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2004-05-10 02:15:57 +0000
committerMichi Henning <michi@zeroc.com>2004-05-10 02:15:57 +0000
commita6a7f49b10372b9e4adf2ac2431b361c5638d156 (patch)
tree1b4e44d9ba7a0209a9faa35b35ce29bb8d4d0e4e /cpp/src/Slice/JavaUtil.cpp
parentFixed VC6 build (diff)
downloadice-a6a7f49b10372b9e4adf2ac2431b361c5638d156.tar.bz2
ice-a6a7f49b10372b9e4adf2ac2431b361c5638d156.tar.xz
ice-a6a7f49b10372b9e4adf2ac2431b361c5638d156.zip
Merged changes from michi_pre_e3 branch
Diffstat (limited to 'cpp/src/Slice/JavaUtil.cpp')
-rw-r--r--cpp/src/Slice/JavaUtil.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index a8060030a0d..883a4f1b736 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -1034,6 +1034,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
}
out << nl << v << " = new " << listType << "();";
out << nl << "final int __len" << iter << " = " << stream << ".readSize();";
+ out << nl << stream << ".startSeq(__len" << iter << ", " << seq->type()->minWireSize() << ");";
if(isObject)
{
if(builtin)
@@ -1065,12 +1066,32 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
out << nl << origContentS << " __elem;";
writeMarshalUnmarshalCode(out, package, seq->type(), "__elem", false, iter, false);
}
- iter++;
if(!isObject)
{
out << nl << v << ".add(__elem);";
}
+
+ //
+ // After unmarshaling each element, check that there are still enough bytes left in the stream
+ // to unmarshal the remainder of the sequence, and decrement the count of elements
+ // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences
+ // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to
+ // abort unmarshaling for bogus sequence sizes at the earliest possible moment.
+ // (For fixed-length sequences, we don't need to do this because the prediction of how many
+ // bytes will be taken up by the sequence is accurate.)
+ //
+ if(!SequencePtr::dynamicCast(seq->type()))
+ {
+ //
+ // No need to check for directly nested sequences because, at the at start of each
+ // sequence, we check anyway.
+ //
+ out << nl << stream << ".checkSeq();";
+ }
+ out << nl << stream << ".endElement();";
out << eb;
+ out << nl << stream << ".endSeq(__len" << iter << ");";
+ iter++;
}
}
}
@@ -1215,6 +1236,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
isObject = true;
}
out << nl << "final int __len" << iter << " = " << stream << ".readSize();";
+ out << nl << stream << ".startSeq(__len" << iter << ", " << seq->type()->minWireSize() << ");";
if(isObject)
{
if(b)
@@ -1250,8 +1272,31 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
writeMarshalUnmarshalCode(out, package, seq->type(), o.str(), false, iter, false);
}
- iter++;
+
+ //
+ // After unmarshaling each element, check that there are still enough bytes left in the stream
+ // to unmarshal the remainder of the sequence, and decrement the count of elements
+ // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences
+ // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to
+ // abort unmarshaling for bogus sequence sizes at the earliest possible moment.
+ // (For fixed-length sequences, we don't need to do this because the prediction of how many
+ // bytes will be taken up by the sequence is accurate.)
+ //
+ if(seq->type()->isVariableLength())
+ {
+ if(!SequencePtr::dynamicCast(seq->type()))
+ {
+ //
+ // No need to check for directly nested sequences because, at the at start of each
+ // sequence, we check anyway.
+ //
+ out << nl << stream << ".checkSeq();";
+ }
+ out << nl << stream << ".endElement();";
+ }
out << eb;
+ out << nl << stream << ".endSeq(__len" << iter << ");";
+ iter++;
}
}
}