ヘッダー検証付きobj.load(image)を両エンジンで実装

このコミットが含まれているのは:
routersys committed 2026-06-29 10:08:59 +09:00
1 親 d2b518f611
コミット cf23d184fe
7ファイル変更
+228 -23

検索条件に一致するファイルはありません

+32 -1
ファイルの表示
@@ -50,6 +50,7 @@ namespace LuaScript.Engine
Func<string, int, SceneObjectInfo?> resolveObject,
Func<string, int, double, double, double, (byte[] buffer, int w, int h)> loadFigure,
Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> loadText,
Func<string, (byte[] buffer, int w, int h)> loadImage,
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
Action<DrawCommand> addDraw,
out bool pixelsDirty,
@@ -105,7 +106,7 @@ namespace LuaScript.Engine
if (status != NativeProtocol.StatusCallback)
break;
DispatchCallback(view, resolveObject, loadFigure, loadText, addEffect, addDraw);
DispatchCallback(view, resolveObject, loadFigure, loadText, loadImage, addEffect, addDraw);
_workEvent.Set();
}
@@ -150,6 +151,7 @@ namespace LuaScript.Engine
Func<string, int, SceneObjectInfo?> resolveObject,
Func<string, int, double, double, double, (byte[] buffer, int w, int h)> loadFigure,
Func<string, string, double, bool, bool, int, (byte[] buffer, int w, int h)> loadText,
Func<string, (byte[] buffer, int w, int h)> loadImage,
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
Action<DrawCommand> addDraw)
{
@@ -165,6 +167,9 @@ namespace LuaScript.Engine
case NativeProtocol.CbKindLoadText:
ResolveLoadTextCallback(view, loadText);
break;
case NativeProtocol.CbKindLoadImage:
ResolveLoadImageCallback(view, loadImage);
break;
case NativeProtocol.CbKindEffect:
ResolveEffectCallback(view, addEffect);
break;
@@ -302,6 +307,32 @@ namespace LuaScript.Engine
view.Write(NativeProtocol.OffCallbackFound, 1);
}
private void ResolveLoadImageCallback(
MemoryMappedViewAccessor view,
Func<string, (byte[] buffer, int w, int h)> loadImage)
{
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
string path = Encoding.UTF8.GetString(_callbackTag, 0, tagLen);
(byte[] buffer, int w, int h) result;
try { result = loadImage(path); }
catch { result = (new byte[4], 1, 1); }
int pixelSize = result.w * result.h * 4;
long capacity = view.Capacity - NativeProtocol.PixelOffset;
if (pixelSize > capacity)
{
result = (new byte[4], 1, 1);
pixelSize = 4;
}
view.Write(NativeProtocol.OffLoadResultWidth, result.w);
view.Write(NativeProtocol.OffLoadResultHeight, result.h);
view.WriteArray(NativeProtocol.PixelOffset, result.buffer, 0, pixelSize);
view.Write(NativeProtocol.OffCallbackFound, 1);
}
private void ResolveEffectCallback(MemoryMappedViewAccessor view, Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect)
{
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
+1
ファイルの表示
@@ -49,6 +49,7 @@ namespace LuaScript.Engine
public const int CbKindDraw = 3;
public const int CbKindDrawPoly = 4;
public const int CbKindLoadText = 5;
public const int CbKindLoadImage = 6;
public const int CbExist = 0;
public const int CbX = 1;