This repository has been archived by the owner on Aug 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 in XK/xenko from virgile/safe_oob_update_engin…
…e to master-1.9 * commit 'a30f222602b8c93f709fe5fb430cb2f6717121df': [UpdateEngine] Skip update if array/list is not big enough (which would otherwise cause memory corruption or exception)
- Loading branch information
Showing
10 changed files
with
174 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
sources/engine/SiliconStudio.Xenko.Engine/Updater/EnterChecker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace SiliconStudio.Xenko.Updater | ||
{ | ||
/// <summary> | ||
/// Provides a way to perform additional checks when entering an object (typically out of bounds checks). | ||
/// </summary> | ||
public abstract class EnterChecker | ||
{ | ||
/// <summary> | ||
/// Called by <see cref="UpdateEngine.Run"/> to perform additional checks when entering an object (typically out of bounds checks). | ||
/// </summary> | ||
/// <param name="obj">The object being entered.</param> | ||
/// <returns>True if checks succeed, false otherwise.</returns> | ||
public abstract bool CanEnter(object obj); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
sources/engine/SiliconStudio.Xenko.Engine/Updater/ListEnterChecker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace SiliconStudio.Xenko.Updater | ||
{ | ||
/// <summary> | ||
/// Implementation of <see cref="EnterChecker"/> for <see cref="IList{T}"/>. | ||
/// </summary> | ||
class ListEnterChecker<T> : EnterChecker | ||
{ | ||
private readonly int minimumCount; | ||
|
||
public ListEnterChecker(int minimumCount) | ||
{ | ||
this.minimumCount = minimumCount; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override bool CanEnter(object obj) | ||
{ | ||
return minimumCount <= ((IList<T>)obj).Count; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
sources/engine/SiliconStudio.Xenko.Engine/Updater/UpdatableArrayAccessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace SiliconStudio.Xenko.Updater | ||
{ | ||
/// <summary> | ||
/// Defines how to get and set an array value for the <see cref="UpdateEngine"/>. | ||
/// </summary> | ||
public class UpdatableArrayAccessor<T> : UpdatableField<T> | ||
{ | ||
public UpdatableArrayAccessor(int index) : base(0) | ||
{ | ||
Offset = UpdateEngineHelper.ArrayFirstElementOffset + index * Size; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override EnterChecker CreateEnterChecker() | ||
{ | ||
// Compute index | ||
var index = (Offset - UpdateEngineHelper.ArrayFirstElementOffset)/Size; | ||
|
||
// Expect an array at least index + 1 items | ||
return new ListEnterChecker<T>(index + 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters