Skip to content

Commit f28fce3

Browse files
ctf: Use declared length as size for BlobDefinitions
Change-Id: I30afb71bbcf7ff688590b95b7f48caf53b9d3ed4 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
1 parent 59e2e33 commit f28fce3

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/BlobDeclaration.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ public BlobDeclaration(int len, String mediaType, String role) {
6363

6464
@Override
6565
public @NonNull BlobDefinition createDefinition(IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull BitBuffer input) throws CTFException {
66-
if (fLength > getMaximumSize()) {
67-
throw new CTFException("Length asked: " + fLength + " is larger than the maximum blob size " + getMaximumSize()); //$NON-NLS-1$ //$NON-NLS-2$
68-
}
6966
byte[] array = new byte[fLength];
7067
if (input.getByteBuffer().remaining() < fLength) {
7168
throw new CTFException("There is not enough data provided. Length asked: " + fLength + " Remaining buffer size: " + input.getByteBuffer().remaining()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -86,12 +83,9 @@ public long getAlignment() {
8683
return 8;
8784
}
8885

89-
/**
90-
* Arbitrary decision to have maximum size as 1MB
91-
*/
9286
@Override
9387
public int getMaximumSize() {
94-
return 1000000;
88+
return fLength * 8; // This will allow the blob to be read properly and not break alignment in ctf.
9589
}
9690

9791
@Override

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/tsdl/struct/StructParser.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.eclipse.tracecompass.internal.ctf.core.event.types.StructDeclarationFlattener;
3131
import org.eclipse.tracecompass.internal.ctf.core.utils.JsonMetadataStrings;
3232

33+
import com.google.gson.JsonElement;
34+
3335
/**
3436
*
3537
* Structures are aligned on the largest alignment required by basic types
@@ -197,19 +199,18 @@ public StructDeclaration parse(ICTFMetadataNode struct, ICommonTreeParserParamet
197199
structBody = struct;
198200
}
199201
} else if (struct instanceof JsonStructureFieldMemberMetadataNode) {
200-
ICTFMetadataNode innerNode = struct.getChild(JsonMetadataStrings.STRUCT);
201-
if (innerNode instanceof JsonStructureFieldMetadataNode) {
202-
JsonStructureFieldMetadataNode structNode = (JsonStructureFieldMetadataNode) struct;
203-
if (structNode.getMinimumAlignment() != 0) {
204-
structAlign = AlignmentParser.INSTANCE.parse(struct, null);
202+
JsonStructureFieldMemberMetadataNode memberNode = (JsonStructureFieldMemberMetadataNode) struct;
203+
if (memberNode.getFieldClass().isJsonObject()) {
204+
JsonElement minimumAlignment = memberNode.getFieldClass().getAsJsonObject().get(JsonMetadataStrings.MINIMUM_ALIGNMENT);
205+
if (minimumAlignment != null) {
206+
structAlign = minimumAlignment.getAsLong();
205207
}
206-
if (structNode.getMemberClasses() != null) {
208+
JsonElement memberClasses = memberNode.getFieldClass().getAsJsonObject().get(JsonMetadataStrings.MEMBER_CLASSES);
209+
if (memberClasses != null) {
207210
hasBody = true;
208211
structBody = struct;
209-
210212
}
211213
}
212-
213214
}
214215
/*
215216
* If a struct has just a body and no name (just like the song,

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/utils/JsonMetadataStrings.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,8 @@ private JsonMetadataStrings() {
237237
*/
238238
public static final String ELEMENT_FIELD_CLASS = "element-field-class"; //$NON-NLS-1$
239239

240+
public static final String MEMBER_CLASSES = "member-classes"; //$NON-NLS-1$
241+
242+
public static final String MINIMUM_ALIGNMENT = "minimum-alignment"; //$NON-NLS-1$
243+
240244
}

0 commit comments

Comments
 (0)