Skip to content

Commit a19d458

Browse files
authored
Fix for int-overflow in GetDocumentCount() (used for tracing only). (Azure#359)
1 parent 61871ca commit a19d458

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

samples/ChangeFeedProcessor/DocumentDB.ChangeFeedProcessor/ChangeFeedEventHost.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace DocumentDB.ChangeFeedProcessor
8181
/// </example>
8282
public class ChangeFeedEventHost : IPartitionObserver<DocumentServiceLease>
8383
{
84-
const string DefaultUserAgentSuffix = "changefeed-0.3.1";
84+
const string DefaultUserAgentSuffix = "changefeed-0.3.2";
8585
const string LeaseContainerName = "docdb-changefeed";
8686
const string LSNPropertyName = "_lsn";
8787

@@ -854,7 +854,7 @@ private static string ParseAmountFromSessionToken(string sessionToken)
854854
return sessionToken.Substring(separatorIndex + 1);
855855
}
856856

857-
private static int GetDocumentCount(ResourceResponse<DocumentCollection> response)
857+
private static Int64 GetDocumentCount(ResourceResponse<DocumentCollection> response)
858858
{
859859
Debug.Assert(response != null);
860860

@@ -865,9 +865,19 @@ private static int GetDocumentCount(ResourceResponse<DocumentCollection> respons
865865
foreach (var part in parts)
866866
{
867867
var name = part.Split('=');
868-
if (string.Equals(name[0], "documentsCount", StringComparison.OrdinalIgnoreCase))
868+
if (name.Length > 1 && string.Equals(name[0], "documentsCount", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(name[1]))
869869
{
870-
return int.Parse(name[1]);
870+
Int64 result = -1;
871+
if (Int64.TryParse(name[1], out result))
872+
{
873+
return result;
874+
}
875+
else
876+
{
877+
TraceLog.Error(string.Format("Failed to get document count from response, can't Int64.TryParse('{0}')", part));
878+
}
879+
880+
break;
871881
}
872882
}
873883
}

0 commit comments

Comments
 (0)