View Issue Details

IDProjectCategoryView StatusLast Update
0038920FPCRTLpublic2021-05-22 07:55
ReporterMartin Friebe Assigned ToMichael Van Canneyt  
PriorityhighSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Platform64bit IntelOSwin 10 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038920: Crash in TWriter with read only class property = nil
DescriptionTrying to write a component with a readonly class property that is nil will crash in WriteProperty


#0 CLASSES$_$TWRITER_$__$$_WRITEPROPERTY$TPERSISTENT$POINTER+275 at :0
0000001 CLASSES$_$TWRITER_$__$$_WRITEPROPERTIES$TPERSISTENT+116 at :0
0000002 CLASSES$_$TWRITER_$__$$_WRITECOMPONENTDATA$TCOMPONENT+151 at :0
0000003 CLASSES$_$TWRITER_$__$$_WRITEDESCENDENT$TCOMPONENT$TCOMPONENT+51 at :0
0000004 SYSTEM_$$_MAIN_WRAPPER$POINTER$POINTER$$INT64+6 at :0


procedure TWriter.WriteProperty(Instance: TPersistent; PropInfo: Pointer);
....
  PropType := PPropInfo(PropInfo)^.PropType;
  if not Assigned(PPropInfo(PropInfo)^.SetProc) then begin
    if PropType^.Kind<>tkClass then
      exit;
    ObjValue := TObject(GetObjectProp(Instance, PropInfo));
    if not ObjValue.InheritsFrom(TComponent) or
       not (csSubComponent in TComponent(ObjValue).ComponentStyle) then
      exit;
  end;


ObjValue will be nil.

The code should have "not assigned(ObjValue) or" added:

    if not assigned(ObjValue) or
       not ObjValue.InheritsFrom(TComponent) or
       not (csSubComponent in TComponent(ObjValue).ComponentStyle) then
      exit;
Steps To Reproduceprogram Project1;
{$mode objfpc}{$H+}
uses
  Classes;

type

  TMyComponent = class(TComponent)
  private
    FFoo: TComponent;
  published
    property ReadOnly: TComponent read FFoo; // will be nil
  end;

var
  strm: TMemoryStream;
  Driver: TAbstractObjectWriter;
  Writer: TWriter;
  Reader: TReader;
  o: TMyComponent;
begin
  o := TMyComponent.Create(nil);

  strm := TMemoryStream.Create;
  Driver := TBinaryObjectWriter.Create(strm,4096);
  Writer := TWriter.Create(Driver);
  Writer.WriteRootComponent(o);
  Driver.Free;
  Writer.Free;

  strm.Free;
end.
Tagscomponent, rtl
Fixed in Revision49389
FPCOldBugId
FPCTarget4.0.0
Attached Files

Activities

Michael Van Canneyt

2021-05-22 07:55

administrator   ~0130993

Fixed, thanks for reporting!

Issue History

Date Modified Username Field Change
2021-05-21 20:01 Martin Friebe New Issue
2021-05-21 20:08 J. Gareth Moreton Tag Attached: component
2021-05-21 20:08 J. Gareth Moreton Tag Attached: rtl
2021-05-21 20:08 J. Gareth Moreton Priority normal => high
2021-05-21 20:08 J. Gareth Moreton Severity minor => crash
2021-05-21 20:08 J. Gareth Moreton FPCTarget => -
2021-05-22 07:45 Michael Van Canneyt Assigned To => Michael Van Canneyt
2021-05-22 07:45 Michael Van Canneyt Status new => assigned
2021-05-22 07:55 Michael Van Canneyt Status assigned => resolved
2021-05-22 07:55 Michael Van Canneyt Resolution open => fixed
2021-05-22 07:55 Michael Van Canneyt Fixed in Version => 3.3.1
2021-05-22 07:55 Michael Van Canneyt Fixed in Revision => 49389
2021-05-22 07:55 Michael Van Canneyt FPCTarget - => 4.0.0
2021-05-22 07:55 Michael Van Canneyt Note Added: 0130993