View Issue Details

IDProjectCategoryView StatusLast Update
0002093JEDI VCL00 JVCL Componentspublic2004-08-25 04:28
ReportermaxpAssigned ToAHUser 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0002093: JvInterpreter Typ2Size bug (potential GPF and crash!)
DescriptionLet's consider script (pay attention to array of SmallInt declaration):

unit TestUnit;
procedure main;
var
  I: Integer;
  A: array[0..10] of SmallInt;
begin
  for I := 0 to 10 do A[I] := 100*I*I;
  ShowMessage(IntToStr(A[10]));
end;
end.

The Typ2Size function is called while executing this script in function JvInterpreterArrayInit:
....
PP^.ElementSize := Typ2Size(ItemType)
....
It returns 1 for type SmallInt. Below in JvInterpreterArrayInit function the next lines are executed:
....
....
  GetMem(PP^.Memory, ArraySize * PP^.ElementSize); //<<(*)>>
  //ZeroMemory(PP^.Memory, ArraySize * PP^.ElementSize);
  FillChar(PP^.Memory^, ArraySize * PP^.ElementSize, 0);
....
....
while debugging, it is clear that in line marked as <<(*)>> wrong space allocated for array
(only 11 bytes in this example while correct space is 22 bytes for array of 11 elements of SmallInt).
I think it is potentially very dangerous bug!
Additional InformationIt seems that in Typ2Size function (see piece of it):
...
varByte:
  Result := SizeOf(Byte);
varSmallint:
  Result := SizeOf(varSmallint); (*!!*)
varDate:
  Result := SizeOf(Double);
...
line marked as (*!!*) should be
  Result := SizeOf(Smallint);
TagsNo tags attached.

Activities

2004-08-25 03:55

 

JvInterpreterShow0002093bug.zip (1,531 bytes)

2004-08-25 03:56

 

JvInterpreterFix000209bug.zip (41,994 bytes)

maxp

2004-08-25 04:00

reporter   ~0005088

Program in JvInterpreterShow0002093bug.zip demonstrates this bug (element with index 10 of array of small int gets wrong value -- I've got 2826 -- instead of 10).

With fixed version of JvInterpreter all is ok.

AHUser

2004-08-25 04:28

developer   ~0005090

Thanks for the fix. It is now in the CVS.

Issue History

Date Modified Username Field Change
2004-08-25 02:18 maxp New Issue
2004-08-25 03:55 maxp File Added: JvInterpreterShow0002093bug.zip
2004-08-25 03:56 maxp File Added: JvInterpreterFix000209bug.zip
2004-08-25 04:00 maxp Note Added: 0005088
2004-08-25 04:28 AHUser Status new => resolved
2004-08-25 04:28 AHUser Resolution open => fixed
2004-08-25 04:28 AHUser Assigned To => AHUser
2004-08-25 04:28 AHUser Note Added: 0005090