Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Id field of Location changed from int(32bit) to BigInteger(unlimited) #2463

Merged
merged 20 commits into from
Mar 24, 2022

Conversation

shaopeng-gh
Copy link
Collaborator

@shaopeng-gh shaopeng-gh commented Mar 2, 2022

Description:

We found that in SARIF spec, there is no definition of the max length of integer type, whether it is 32 bit, 64 bit or no limit.
Our current SDK code assumes 32 bit, which should be wrong assumption, should be no limit since spec does not mention any limit.

Fixes:

Spot fix the Location.Id to use BigInteger which is no limit.

Note that we should also change the jschema to use BigInteger across the solution. created a issue there:
microsoft/jschema#144

@shaopeng-gh shaopeng-gh changed the title testing build for bigint branch BREAKING: Id field of Location changed from int(32bit) to BigInteger(unlimited) [#2463](https://github.com/microsoft/sarif-sdk/pull/2463) Mar 2, 2022
@shaopeng-gh shaopeng-gh changed the title BREAKING: Id field of Location changed from int(32bit) to BigInteger(unlimited) [#2463](https://github.com/microsoft/sarif-sdk/pull/2463) BREAKING: Id field of Location changed from int(32bit) to BigInteger(unlimited) Mar 2, 2022
@shaopeng-gh shaopeng-gh marked this pull request as ready for review March 2, 2022 06:20
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.0.0")]
public partial class Location : PropertyBagHolder, ISarifNode
Copy link
Collaborator Author

@shaopeng-gh shaopeng-gh Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location

created a copy of the Location.cs to
NotYetAutoGenerated folder to make modification. #Closed

public bool ShouldSerializeId()
{
return Id != -1;
}
Copy link
Collaborator Author

@shaopeng-gh shaopeng-gh Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed because DefaultValue does not work for BigInteger.

then this need 2 things,

  1. in the constructor to set it, which we already have.
  2. ShouldSerializeXXX to handle the serialization. #Closed

@@ -11,6 +11,7 @@
* BUGFIX: Fix `Merge` command produces empty SARIF file in Linux when providing file name only without path. [#2408](https://github.com/microsoft/sarif-sdk/pull/2408)
* BUGFIX: Fix `NullReferenceException` when filing work item with a SARIF file which has no filable results. [#2412](https://github.com/microsoft/sarif-sdk/pull/2412)
* BUGFIX: Fix missing `endLine` and `endColumn` properties and remove vulnerable packages for ESLint SARIF formatter. [#2458](https://github.com/microsoft/sarif-sdk/pull/2458)
* BREAKING: `Id` field of `Location` changed from `int`(32bit) to `BigInteger`(unlimited) [#2463](https://github.com/microsoft/sarif-sdk/pull/2463)
Copy link
Member

@michaelcfanning michaelcfanning Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field

use 'property' not 'field' as a term. Add something about the exception message you see on deserializing a id value larger than 2^31 #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


public bool ShouldSerializeId()
{
return Id != -1;
Copy link
Member

@michaelcfanning michaelcfanning Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Id != -1

return Id >-1; #Closed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit test for this.

location.Id = int.MaxValue;
AssertShouldSerializeId(location, true);

location.Id = long.MaxValue;
Copy link
Member

@michaelcfanning michaelcfanning Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long

add ulong max value #Closed

AssertShouldSerializeId(location, false);

location.Id = -1;
AssertShouldSerializeId(location, false);
Copy link
Member

@michaelcfanning michaelcfanning Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test for long.MinValue - 1
add test for long.MinValue
add test for int.MinValue
add test for -2 #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added all

@@ -85,5 +92,68 @@ public void Location_LogicalLocation_WhenSetToNull_RemovesLogicalLocationsArray(

location.LogicalLocations.Should().BeNull();
}

[Fact]
public void Location_SerializeId()
Copy link
Member

@michaelcfanning michaelcfanning Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location_SerializeId

These tests may not provoke round-tripping issues?

#Closed

Copy link
Collaborator Author

@shaopeng-gh shaopeng-gh Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to round trip

Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shaopeng-gh shaopeng-gh marked this pull request as draft March 9, 2022 22:13
@shaopeng-gh shaopeng-gh marked this pull request as ready for review March 12, 2022 00:58
@shaopeng-gh shaopeng-gh marked this pull request as draft March 16, 2022 23:10
* BUGFIX: Eliminate dispose of stream and `StreamWriter` arguments passed to `SarifLog.Save` helpers. This would result in `ObjectDisposedException` being raised on attempt to access streams after save.
* BREAKING: `Id` property of `Location` changed from `int`(32bit) to `BigInteger`(unlimited) to fix `Newtonsoft.Json.JsonReaderException: JSON integer XXXXX is too large or small for an Int32.` [#2463](https://github.com/microsoft/sarif-sdk/pull/2463)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the very first part "error ERR999.UnhandledEngineException" which only apply to the SDK validate tool.

the rest error message apply to both SDK validate tool and directly using:
JsonConvert.DeserializeObject<SarifLog>(content)

}

[Fact]
public void Location_VerifyAbleToDeserializeWithBigIntegerId()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public void Location_VerifyAbleToDeserializeWithBigIntegerId()

added a new test for JsonConvert.DeserializeObject<SarifLog>(content)
from a SARIF file.

@shaopeng-gh shaopeng-gh marked this pull request as ready for review March 16, 2022 23:17
"level": "note",
"locations": [
{
"id": 31197130097450771296369962162453149327732752356239421572342053257324632475324,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

31197130097450771296369962162453149327732752356239421572342053257324632475324

data in this file contains very long int, 64 int max +1, 32 int max +1 and a few normal ones.

@michaelcfanning michaelcfanning enabled auto-merge (squash) March 24, 2022 16:24
@michaelcfanning michaelcfanning merged commit ed38f39 into main Mar 24, 2022
@michaelcfanning michaelcfanning deleted the users/shaopeng-gh/bigint branch March 24, 2022 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants