Skip to content

Commit

Permalink
Only allow characters and numbers in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 25, 2023
1 parent ec39a5e commit eefffd1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object AttributePickler:
for attribute <- attributes do
val bytes = attribute.getBytes(StandardCharsets.UTF_8).nn
val length = bytes.length
assert("[a-zA-Z0-9]+".r.matches(attribute), "Malformed attribute. Attribute must match [a-zA-Z0-9]+")
buf.writeNat(length)
buf.writeBytes(bytes, length)
end pickleAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AttributeUnpickler(reader: TastyReader):
val length = readNat()
val bytes = readBytes(length)
val attribute = new String(bytes, StandardCharsets.UTF_8)
assert("[a-zA-Z0-9]+".r.matches(attribute), "Malformed attribute. Attribute must match [a-zA-Z0-9]+")
attributesBuilder += attribute
}
attributesBuilder.result()
Expand Down
7 changes: 5 additions & 2 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,13 @@ All elements of a position section are serialized as Ints
Standard Section: "Comments" Comment*
```none
Comment = Length Bytes LongInt // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates.
Comment = UTF8 LongInt // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates.
```
Standard Section: "Attributes" UTF8*
Standard Section: "Attributes" Attribute*
```none
Attribute = UTF8 // attributes match the regex [a-zA-Z0-9]+
```
**************************************************************************************/

Expand Down

0 comments on commit eefffd1

Please sign in to comment.