Skip to content

Conversation

@fredroy
Copy link
Contributor

@fredroy fredroy commented Jan 29, 2026

Different overflows risk were not checked,
and one array access is a bug (in BaseContactMapper)

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy fredroy added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: ai-generated Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Jan 29, 2026
…reading and writing same buffer).

  Fixed:
  sscanf(buf, "%*127s %127s", matName);

  Breaking down the format:
  - %*127s - The * is the assignment suppression modifier. It means "read up to 127 chars but discard them (don't store)". This skips the first word (like "newmtl")
  - %127s - Read the second word (the material name), limited to 127 chars, store in matName

  So if buf contains "newmtl MyMaterial\n":
  - %*127s reads and discards "newmtl"
  - %127s reads "MyMaterial" into matName

  The 127 limit prevents buffer overflow since matName is 128 bytes (127 chars + null terminator).
… buffer overflows from size calculation wraparound
@fredroy fredroy force-pushed the fix_vulnerabilities_overflows branch from cbcd999 to e942da9 Compare January 29, 2026 03:53
@fredroy
Copy link
Contributor Author

fredroy commented Jan 29, 2026

[ci-build][with-all-tests]

result.resize(length);
for (int i = 0; i < length; i++)
result[i] = alphanum[rand() % length];
result[i] = alphanum[rand() % alphanum.size()];
Copy link
Contributor

Choose a reason for hiding this comment

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

😮‍💨

Comment on lines +56 to +61
inline bool wouldOverflowCompliance(unsigned int a, unsigned int b)
{
if (a == 0 || b == 0) return false;
return a > std::numeric_limits<unsigned int>::max() / b;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, not impressed... Why not in the meantime increase the size of the variable ? unsigned long ?

vecString vLine;

char *l = new char[line.size()];
char *l = new char[line.size() + 1];
Copy link
Contributor

Choose a reason for hiding this comment

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

For the \0 char ?

mat->name = buf;
{
char matName[128] = {0};
sscanf(buf, "%*127s %127s", matName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I don't understand this code.

Comment on lines +865 to +871
if (lines.empty())
{
m.resize(0, 0);
if( in.rdstate() & std::ios_base::eofbit ) { in.clear(); }
return in;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Unecessary quick return... To be removed IMO

Comment on lines +32 to +38
{
template<typename Index>
bool wouldOverflowBlock(Index a, Index b)
{
if (a <= 0 || b <= 0) return false;
return a > std::numeric_limits<Index>::max() / b;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Many definitions of this same function, why not put it in a util file somewhere ?


namespace
{
template<typename Index>
Copy link
Contributor

Choose a reason for hiding this comment

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

SAme, could be replaced by a call to the util method with b=3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: ai-generated Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants