Add new memo restrictions

This commit is contained in:
David Schwartz
2014-06-23 10:43:41 -07:00
committed by Nik Bougalis
parent b06bdb83cb
commit a5297d13c4
2 changed files with 29 additions and 1 deletions

View File

@@ -318,13 +318,40 @@ bool isMemoOkay (STObject const& st)
{
if (!st.isFieldPresent (sfMemos))
return true;
const STArray& memos = st.getFieldArray (sfMemos);
// The number 2048 is a preallocation hint, not a hard limit
// to avoid allocate/copy/free's
Serializer s (2048);
st.getFieldArray (sfMemos).add (s);
memos.add (s);
// FIXME move the memo limit into a config tunable
if (s.getDataLength () > 1024)
return false;
for (auto const& memo : memos)
{
auto memoObj = dynamic_cast <STObject const*> (&memo);
// Memos array must consist solely of Memo objects
if (!memoObj || (memoObj->getFName() != sfMemo))
{
return false;
}
// Memo objects may only contain
// MemoType, MemoData, and MemoFormat fields
for (auto const& memoElement : *memoObj)
{
if ((memoElement.getFName() != sfMemoType) &&
(memoElement.getFName() != sfMemoData) &&
(memoElement.getFName() != sfMemoFormat))
{
return false;
}
}
}
return true;
}

View File

@@ -162,6 +162,7 @@ FIELD (ExpireCode, VL, 10)
FIELD (CreateCode, VL, 11)
FIELD (MemoType, VL, 12)
FIELD (MemoData, VL, 13)
FIELD (MemoFormat, VL, 14)
// account
FIELD (Account, ACCOUNT, 1)